-
Notifications
You must be signed in to change notification settings - Fork 103
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
Static type checking #621
Comments
Thanks for the suggestion. I love type checking, but I'm really cautious about introducing a static analysis tool in python because of the amount of false positive. Python being a dynamically typing language, I'd prefer the tool to fit our codebase (with minor adjustments) instead of fitting our codebase to the tool. I don't want to restrict contributors by annoying them with false positives or forcing them to add types where it's obvious. If you're willing to work on this, the path forward would be to add static type checking but with a minimal amount of rules and adding more and more rules progressively and see if our code is compatible. I don't want to tool to force us to write things a certain way, I would like the tool to point actual errors :) |
Type checkers are relatively "new" to Python, and is constantly developed so false positives will absolutely be present. Speaking from personal experience, I introduced static typing into an already existing codebase. It would be impossible to set "strict" mode at once. I used pyright, and initially set it to Basic. Then I gradually introduced more rules. As I mentioned earlier, i got most experience with |
I don't have an opinion about pyright vs mypy. If you want to push on this work and are familiar with pyright, go for it! |
python-on-whales/python_on_whales/command_line_entrypoint.py Lines 34 to 45 in 338feb5
Tried to apply the basic set of rules. A typical problem i see is like the example above. The
That means that if What would be the best way to fix this? To keep backwards compatibility, the arguments and its types should probably not be changed. How about raising an exception inside the |
Indeed I don't believe this is a false positive here. This is a real error in our code. We are just missing checks. A user could call our function with |
Hey
I think a great addition to this project would be to add a static type checker. I think the two most widely used are
pyright
andmypy
.Both have support for having some "basic" typechecking initially, then expanding one rule at the time, which is the most feasible way when adding it in a existing project.
I would be happy to provide a PR :) Personally i have most experience with
pyright
, but open for whatever you think is bestThe text was updated successfully, but these errors were encountered: