-
-
Notifications
You must be signed in to change notification settings - Fork 343
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
add type tests for all exported objects #2623
Conversation
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## master #2623 +/- ##
==========================================
+ Coverage 92.27% 92.43% +0.15%
==========================================
Files 118 118
Lines 16352 16352
Branches 3156 3156
==========================================
+ Hits 15089 15115 +26
+ Misses 1146 1114 -32
- Partials 117 123 +6 |
950722b
to
4edfd3d
Compare
oh goodness generating requirements.txt is a nightmare. I may have finally succeeded after the nth try, but github seems to be struggling atm. It may be possible to freeze some version somewhere that supports 3.7 to not need to remove |
Oh my god. When did Python get to the point of testing type annotations????????? I'm no authority but if you are ever at the point of having to run tests for types you have done something very very wrong. Absolutely, vehemently against this. |
I don't quite understand the point of this PR FWIW. I can see two potential points, though:
This is the explicit goal of things like The reason why it's explicitly called
I think pyright's "type completeness" score is a better metric of this (it also checks some more stuff like "are we relying on mypy's inference behavior" (which isn't specified to work for all type checkers)), though I'm not sure how to make sure we only increase it. See https://github.com/microsoft/pyright/blob/main/docs/typed-libraries.md#type-completeness (and https://github.com/microsoft/pyright/blob/main/docs/typed-libraries.md#verifying-type-completeness for checking it). Basically, would you mind elaborating on the point of this PR? I might be missing something! |
Indeed writing tests for all the annotations isn't really useful. Typeshed does have tests, but only for a select few things. It's used either for complicated functions like For doing type tests, there's actually now a standard way to do tests that will work with both mypy and pyright. Simply use |
Thank you for the constructive comments! I'll close this and rethink the approach :) |
Turns out It would likely also warrant moving reopened in case of further discussion |
I support this. Kill |
alternative ways of solving this are superior and I'm making decent progress on them. |
As a prelude towards deprecating trio-typing (see https://github.com/python-trio/trio-typing), and more work on #543 I'm adding the ability to test types with https://github.com/typeddjango/pytest-mypy-plugins (as suggested in python-trio/trio-typing#10).
Also adding tests for all currently exported objects that has some type annotations (note that those are not visible to users currently due to trio not being marked with
py.typed
though), and a living list of all remaining objects that are not typed which can be thinned out as more exports get typed - and if/when that gets emptied or thin enough we can retiretrio-typing
and marktrio
as fully typed without having to have fully typed all the internals.One could also copy this test over to trio-typing to see that the types are in accordance with the stubs (the stubtest added in python-trio/trio-typing#73 will mostly achieve that, but that's a separate CI), and/or set up a test environment here that installs the stubs from trio-typing and reruns tests.
I'm a bit unsure whether to remove the temporary
py.typed
file incheck.sh
- on one hand you want it there if you want to run pytest locally, but on the other hand it might be accidentally pushed or if you're running a separate application against the dev environment the existence of py.typed might mess with type checking. I'll probably change to removing it if it didn't exist before check.sh ran, and add a dedicated test that checks for the existence of it and gives a more helpful error message than what pytest-mypy-plugins will give when testing the yaml file. Or maybe it's possible to add some fancy extension hook or something https://github.com/typeddjango/pytest-mypy-plugins#options