-
Notifications
You must be signed in to change notification settings - Fork 258
clarify "should only check function signatures in stub files" #99
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
Comments
I meant some approximation of (1). Classes and type aliases and a few other things should also be checked -- I really just meant that the checker should not insist on a return statement with an appropriately typed value, nor try to type-check any code in function bodies in stubs. But (2) is also true -- the idea is that a type checker should entirely ignore the implementation if it has a stub. (Although at least Google wants to cross-check stubs with implementations too -- but that's outside the scope of the PEP.) |
We discussed (2) with Jukka and Łukasz at PyCon and we agreed that for a *.pyi file a type checker should be allowed to read the definitions from the corresponding *.py file if it is necessary for the checker. There are two scenarios when this is helpful:
|
But isn't that a Quality of Implementation issue for the type checker? If not, do you have a specific suggestion for what the PEP needs to say? |
@gvanrossum Yes, it should be up to the type checker. Maybe we could add something like "If there is a stub file for the *.py file available, then a type checker may ignore the corresponding *.py file or use it to extend the information in the stub." |
I like what vlasovskikh wrote, but just before that I would say something like: The interface file is intended only to declare static type information, similar to what is provided by an inspect.Signature object. Therefore, this PEP does not standardize any meaning for the bodies of stub functions; notably, stub functions are not required to contain return statements, even when the function is documented with a returns annotation. this PEP does |
Is the PEP explicitly blessing typeshed as the standard 3rd party repository, analogous to PyPI? Even if it is, it still might be useful to specify that PEP is not standardizing interpretation of anything in interface files beyond the typing module's own vocabulary and things that inspect.Signature cares about. (In other words, typeshed might or might not attribute meaning to function bodies or raise statements sometime Real Soon Now, but python itself isn't yet recognizing those meanings as standard.) |
The PEP is not explicitly blessing typeshed. I still believe the language in the PEP is all we need. |
Does that mean that
(1) Everything in the stub/interface file except function signatures signatures should be ignored?
or
(2) If there is a stub file, then annotations in the true source file should be ignored. This supports simpler annotations for documentation and more precise annotations for type-checking.
The text was updated successfully, but these errors were encountered: