-
Notifications
You must be signed in to change notification settings - Fork 20
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
Utility to validate stubfile signatures against .py implementations #100
Comments
Besides validating, there could be a fixer tool to add missing definitions to the stubfile, and if there are incompatible definitions I'd expect both tools to notice and warn you. |
Note on the use case: A starting point may be https://github.com/Stewori/pytypes/blob/master/pytypes/stubfile_manager.py#L55 Note: |
That's true stubfiles aren't just for py 3.4 compatibility. I thought C-extensions wouldn't be feasible to cross-check and typeshed seemed "legacy" per comments like python/typeshed#3991 (comment). Anyway, sorry if I undersold the value. Actually mypy does have a stubtest tool that seems related, but it doesn't seem to complain if I delete things from pyi or mess up signatures. |
I think that should work based on inspection just like ordinary python modules, except that type annotations are only possible via stubfiles. But disclaimer: I did not actually test this so far.
Honestly, I did not follow the fate of typeshed recently but I just had a quick look at their landing page and there is no deprecation statement whatsoever. I learned that mypy bundles typeshed, so it is much invisible to the user though. (Maybe I or we should consider how to improve typeshed integration for pytypes but that's again a different story.)
If you already figured it out, would you paste a usage instruction or ideally a small script that applies it to the upcoming pytypes' |
It would be useful to have utilities to validate stubfiles against the .py implementations to ensure the definitions are compatible and complete.
If a stubfile foo.pyi exists in a library the typecheckers seem to completely ignore the corresponding foo.py file (at least in the case of mypy), so the typechecker will spit out "no such attribute" errors if you try to reference definitions you add in foo.py but forget to add it in foo.pyi. It would be nice to have a validator for library maintainers to easily include in their library's test suites to make sure the .pyi is up to date and contains at least as much type information as the .py file.
Note this is geared towards library maintainers that want to maintain compatibility with python 3.4 and earlier. Otherwise you can simply embed the type hints directly in the .py and there's no duplicate definition to keep in sync.
The text was updated successfully, but these errors were encountered: