-
Notifications
You must be signed in to change notification settings - Fork 96
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
Enable types in podman package #293
Comments
SGTM |
SGTM, the project has used type hints since day one. @francisbergin Do you see this new tool a compliment or replacement to the current use of pylint? Addressing #292 would be a great test of the chosen tool. |
Hi! The chosen tool would be a compliment to Pylint which would focus on type checking. The main tools available that I am aware of are Mypy, Pyright, Pyre and Pytype. I believe the basic functionality should be quite similar between these 4 projects. I started #294 as a POC of changes required to get the type checker to pass. The first run had 331 type errors and the current run with fixes has 179 errors. In this PR, I adapted the type hints to the code but perhaps in some cases the code needs to be adapted to the type hints. Please let me know what you think of the changes so far and if it is worth continuing the effort. Note that for this specific issue, the change would just be to add a py.typed file to the published package which would allow users to type check their usage of the podman package. Thank you! |
We've been using mypy for qemu.qmp and for the internal qemu packages in the qemu tree. It's OK. In the areas where it leaves something to be desired, it feels mostly like shortcomings with Python's typing system and not necessarily problems with mypy itself. The error messages are a little misleading and terse at times, but it's overall pretty decent. Cross-version compatibility usually seems to be quite good compared to e.g. pylint which sometimes lags behind new Python beta releases. I've used vscode and pycharm somewhat sparingly, I don't know what they use to power type checking. (I am unfortunately an emacs gremlin most of the time and can't speak towards the quality of IDE integrations available. Occupational hazard of working with other QEMU developers.) I have not used Pyright, Pyre nor Pytype. I could explore those other tools to see what they might offer that mypy doesn't; I had some notion that mypy was for better or worse the reference implementation. I know I have seen Pyre discussed at the Python typing summit a few years back, and it seems optimized for speed on huge codebases but I don't know if that focus comes with a caveat or not. |
Adding a
py.typed
file in the root of thepodman
package would allow type checking for it in projects that use the package.For example, the following script:
Would not cause any mypy errors (issues would be caught at runtime):
But with the
py.typed
file, we can catch the issues earlier:Maybe package type issues should be fixed in #292 before enabling type information in the package?
The text was updated successfully, but these errors were encountered: