-
Notifications
You must be signed in to change notification settings - Fork 93
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
Type chaining #182
Type chaining #182
Conversation
tasks.py
Outdated
"python scripts/chaining_type_generator.py" | ||
" AllFuncs src/pydash/chaining/all_funcs.pyi Chain" |
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.
nit: This can fit on a single line.
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.
Actually, I think it'd be easier to grok if these were named arguments instead of positional.
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 used named arguments there, makes it a bit nicer
Excellent work! I don't see any major issues in the code after a first-pass review. To address your points:
Where are the hard coded imports? I see a
Do you think the tests we have for chaining + all the other types has sufficient coverage? Wondering if there's enough confidence with what's there now or if something changes that breaks typing that it would get caught by the tests? The pydash API is pretty stable so I don't anticipate any major changes to argument types so seems like it's more of a concern of not taking other type usage into account.
Is there a way to assert/check that the generate types are out of sync? If there's a way to include that as a test, then that would be preferable. Thinking something similar to the |
I mean all the imports in the
Since chaining simply reuses the functions' types, I didn't add too many typing checks for chaining, just enough to check that chaining methods works. But if the functions' types are right, chaining should be typed well too. However I don't think we have all typing paths checked in the typing tests. They could be added later if we find some typing problems to validate a fix. I think they should be enough to validate a change for the main use cases. To be honest even just running mypy should be able to catch most problems with argument types changes. I removed the stub file from the excluded list of mypy, just ignored the misc error code. It should catch most problems in the generated stub, already made a few fixes from it.
I think your proposed solution is the easiest and it would work very well so I added it. A new |
tasks.py
Outdated
@@ -28,37 +31,40 @@ | |||
|
|||
|
|||
@task | |||
def black(ctx, quiet=False): | |||
def black(ctx, target: t.Optional[str] = None, quiet=False): |
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.
If adding types to these tasks, might as well add them to all the args and returns for consistency.
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.
Oh yeah, this looks bad, I didn't even realize I added types among non typed arguments :D
I rebased and updated the stub file to integrate the change in the other PR (lint task correctly told me it needed update, it is cool :))
And I typed all tasks fully.
7b1add0
to
a6dfe82
Compare
Here is my take on typing the chaining interface.
The idea is to make the chain class generic on the virtual current value (the one that would be computed at this stage) and generate a stub file for the chain class that has all the exposed functions of the library as methods. The self parameter is the chain class generic on the expected first parameter of the function and the return type is another chain class generic on the result of the function.
This seems to work well.
Some possible improvement points:
pydash.types
and the modules would import from there. Then we would just have to import all frompydash.types
in this script.Chain
asself
types but it is in aAllFuncs
class which mypy doesn't like, hence the exclude.