-
-
Notifications
You must be signed in to change notification settings - Fork 369
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
Investigate Type Annotation #439
Comments
Hi @iwoloschin! I'm super keen on getting type annotations throughout pyinfra, but as you say this is essentially on hold until v2 which will drop python 3 support. Also interesting is that pyright issue - the operation decorator (currently) uses |
I played around with that pyright workaround, it does work for passing the operation's normal arguments forward through the Unfortunately, that doesn't do anything to help with the global arguments. The only way I've found to get that to work is to manually define them (again, I did this in a separate Separately, it seems that Anyways, I'll probably continue to play with typing stubs (https://mypy.readthedocs.io/en/stable/stubs.html), would you be interested in PRs? |
It does indeed look like python/typing#193 might cover that use case! Long term I'd like type annotations inline but I'm open to PRs implementing stub as they can be merged in easily once py2 is dropped :) Regarding the host/inventory/state - these are implemented as pseudo modules with a base class, might be possible to leverage that somehow? |
I've made a PR #444 to try getting the bare minimum typing information for supporting the If you're comfortable merging in #444 then I can start adding typing stubs for all of the operations. I'll look into the |
@Fizzadar I noticed you referenced python/typing#193 on variadic generics in this thread. Heads up that we've been working on a draft of a PEP for this in PEP 646. If this is something you still care about, take a read and let us know any feedback in this thread in typing-sig. Thanks! |
I've found lack of types not that bad since there are decent docs and pyinfra seems well tested. But for my own custom deploys I'm more worried about messing them up. For anyone who wants to at least type their own deploys, you can use this trick:
Then stuff like this will be type checked:
You can also probably use it for typing some of pyinfra's API on ad-hoc basis |
Typing is now in! Not 100% but mypy is part of CI and types can gradually be introduced. The global operation args are typed. |
Is your feature request related to a problem? Please describe.
I just started exploring pyinfra and so far I like it a lot. I happen to use VSCode with the Pylance plugin. This appears to throw a ton of red squiggles on anything decorated with the
@operation
decorator ifType Checking Mode
is set tobasic
. The completion/help for any function arguments is also broken. I suspect the issue is related to microsoft/pyright#774, but I'm not sure how to deal with how the@operation
decorator adds global arguments.Describe the solution you'd like
I suspect providing type annotations for the entire project is out of scope (for now... 😄 ), but it would be interesting to explore how to better support some basic type annotations. This may be more of a v2 problem though.
The text was updated successfully, but these errors were encountered: