-
Notifications
You must be signed in to change notification settings - Fork 64
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
Adds type hints to public API. #407
Conversation
Somewhat unrelated, but from Python 3.9, we have https://docs.python.org/3.9/library/ast.html#ast.unparse – might be useful to avoid the AST code generation code altogether. |
The But alternatively, why not just import |
I mean it's a top level import, if any shadowing was going on it would shadow the other way, and if it did and had any sort of effect on the type annotations, then type checkers would complain, loudly. I like this style for <3.10 because it avoids having a ton of typing specific imports. Starting with 3.9 and 3.10 you can get rid of a lot of those imports for the new union syntax and subscriptable builtin types and ABCs. If you don't mind a |
Pull Request Test Coverage Report for Build 7346414880
💛 - Coveralls |
I think we could probably bump up to Python 3.10 to benefit more from this typing endeavor – if not in this pull request, then perhaps after the next release. |
I think a bump to 3.10 is maybe a bit aggressive, but a bump to 3.9 seems reasonable considering 3.8's EOL is less than a year away, then you could also work on your unrelated improvement/simplification to code generation. If we use deferred annotations using |
I don't know if for example the Python RPMs built for Chameleon are .pyc-files only (see #348), but they could be and that would take care of such an overhead for perhaps more enterprise-oriented users. |
Yes, I think we could bump to 3.9. Perhaps it's reasonable enough to cut a release now and then introduce typing in the next release, with a 3.9+ requirement to boot. |
The type annotations are also present in byte code, so they would cause overhead either way, as long as they're evaluated at runtime, the The majority of that overhead stems from generics, since things like |
I updated the type hints to the modern style. I also added a flake8 plugin which should help with minimizing the runtime overhead of type annotations. It will warn about things like imports that are only used in type annotations so they can be moved inside a |
Updates isort config. Removes some more PY2 cruft.
I already had some stubs lying around for |
I'll merge this – let's iterate on the master branch on improvements and further changes. |
Closes #405
I tried to keep the diff relatively small, but I also wanted to enable a relatively strict mypy config for the public API, so I ended up annotating a bit more to guarantee a robust basis.
I also ran autotyping once which uses black to auto format the code, so there are a few formatting changes that have nothing to do with type annotations, but I made sure to revert most of them, to keep the diff as small as possible.
I also removed some of the leftover Python 2.7 compatibility stuff in the places where mypy wasn't happy about it.
I added a mypy environment to the tox config and added it to the matrix for github actions.
This also adds a minimal
pyproject.toml
. Some of the tool configuration could be moved fromsetup.cfg
topyproject.toml
but for now it's probably not worth the effort, especially since flake8 doesn't supportpyproject.toml
yet and tox only sort of supports it by pasting the entiretox.ini
in a multiline string inside thepyproject.toml
.