-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
index operator interface #165
Conversation
Codecov Report
@@ Coverage Diff @@
## master #165 +/- ##
==========================================
+ Coverage 92.78% 92.82% +0.03%
==========================================
Files 86 86
Lines 6639 6703 +64
==========================================
+ Hits 6160 6222 +62
- Misses 479 481 +2
Flags with carried forward coverage won't be shown. Click here to find out more.
... and 1 file with indirect coverage changes 📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
Please consider setting up pre-commit, having the ci bot create merge commits for pre-commit changes does not allow rebaseing and requires cherry picking all commits in a new branch. Anyway - have a look, I sneaked in some bit's I have had and added a unit test. |
I'm not familiar with pre-commit, but it looks simple to use. Is there anything I need to do beyond the following?
It seems to get stuck on the |
It does not allow committing non-compliant changes.
|
Small QOL update to the OperationIndex class that adds the __getitem__ method to enable access to operations via index operations (square brackets).
If the key is None, instead of looking based on path + method it will search for the operationId. This is slightly slower than dict comprehension, but still quick and the code is a bit more readable. A path's non-operation objects are also kept. (cherry picked from commit 6b58d47)
Never merge, always rebase. I rebased this to allow merging. |
If you want to incooperate the use of operationIds in Reduce I think it'll be better to have the Reduce.operations a List instead of a dict.
Using a dict will do as well, it's basically {None:["operationIdA","operationIdB"], r'/test':["get"]} vs ["operationIdA", "operationIdB", (r"/test", ["get"])] where the use of a tuple or a str is similar to the parameters when creating a request. |
I considered that as well as breaking it out into two separate arguments:
is the way to go. Using a tuple also make sense, since the incoming filters should be immutable. I'll update the PR today. |
but then I thought if patterns was the right tool on the very defined and limited number of http methods, if it would improve anything but increase complexity. That said - I'd prefer List[
Union[
Tuple[
Union[Pattern,str],
Optional[
List[
Literal["get","put", "post", "delete","options","head","patch","trace"]
]
]
],
str
]
] |
No idea about the github app, never used it. And I can imagine it is not happy about me re-basing and force pushing your branch. |
tests/extra_test.py
Outdated
return ctx | ||
|
||
|
||
class MSGraphCulled(MSGraph, Cull): | ||
pass | ||
def paths(self, ctx: "Init.Context") -> "Init.Context": | ||
return ctx |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Cull/Reduce paths() would set ctx.paths non and limit the initialization of schemas to schemas identified as required by tracking the schemas required for the operations.
Why avoid this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I forget specifically what I was testing for there, but I think I was investigating something to do with schemas being ignored when they shouldn't be.
ADHD moment... It can be set back to pass
for now, and I'll jump back into that investigation later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove - so the super() can take care.
tracking failing is a bug we'll address properly, if you find the schema/selectors required to reproduce.
Adjusted the Reduce class to handle a list of operations rather than a dict of path and methods. A string or pattern can be used in the list to match against operationIds, or a tuple with a string or pattern as the first element representing the path and a list of strings representing HTTP verbs as the second element will match against the path/methods. Also, in any case that a path is not culled, the non-operation keys are kept intact to maintain defaults and overrides. The MSGraph test was updated to accommodate the annotation change as well as to handle a few validation fixes. (cherry picked from commit 21b8dfb)
I adjusted the unit tests. Now - as we work with a list, question … Reduce(list) or Reduce(*list) class Reduce(Document, Init):
def __init__(
self,
operations: List[
Union[Tuple[Union[re.Pattern, str], Optional[List[Union[re.Pattern, str]]]], Union[re.Pattern, str]]
],
) or class Reduce(Document, Init):
def __init__(
self,
*operations: List[
Union[Tuple[Union[re.Pattern, str], Optional[List[Union[re.Pattern, str]]]], Union[re.Pattern, str]]
],
) As I do not exactly know if the typing is correct for the last one, example: Reduce([("test",None), "test2"]) vs Reduce(("test",None), "test2") |
Small QOL update to the
OperationIndex
class that adds the__getitem__
method to enable access to operations via index operations (square brackets).