-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Adding platform information to stdlib/VERSIONS #11260
Comments
Is there a concrete reason for doing this now, or is this this just theoretical? If it's just theoretical, I'd prefer to hold off until there's a proven need for this facility. |
The need is the same as for initially adding VERSIONS: Addressing a deficiency in how type checkers can detect whether stubs are available in a certain Python version. But the concrete trigger was #6749/#11241: Having a solid way to say "This package doesn't exist on this platform in the stdlib" would enable a third-party stubs package to reliably add that package without interfering with a stdlib package. |
Also just to clarify: There would be no need to immediately implement this on the type checker side and there is also no pressing need on typeshed's side to remove the version_info checks when this gets implemented. This is as possible timeline:
Then type checkers have the option to implement the new-style checks. I expect typeshed to keep the current in-stub checks for at least as long as the major type checkers haven't implemented the new-style checks. |
OK, makes sense. I've added provisional support for the above proposal in pyright. If we end up modifying the proposal, I will adjust accordingly. I presume that if there are one or more platforms listed without |
I'm not convinced that this is a good idea. Currently the syntax of the VERSIONS file is super simple, and I'd prefer to leave it that way instead of inventing a complex language that is only used to describe one file. Also, the VERSIONS file is supposed to contain info about standard library specific things. To me, "Python version added" is clearly a standard-library thing while "supported platforms" could apply to any stub file. So if we do this for standard-library stubs, it would be tempting to do something similar for third-party stubs, which would introduce even more complexity for little benefit. To me, the only convincing reason is better type checker error messages, because users would see it. |
That's a good point. A generic way to tell type checkers "this module is not available on that platform" would be preferable. That said, amending VERSIONS is better than the status quo. I don't think keeping VERSIONS super simple should be a design goal, as it's not user facing. Also, to me, the proposed format is simple enough, and only used for a few modules. |
A bit weird, but maybe type checkers could just check if everything in the stub file (except imports) is defined inside a Advantages:
Disadvantages:
|
Echoing @Akuli, adding platform information to
|
Ideally, both platform and Python version availability would be encoded in the stub file itself instead of an external file. But for now I think Rebecca's suggestion to use a |
I think I'd prefer to implement Rebecca's second suggestion. This would not require a new special file format, and it would generalize to third-party packages more easily. Suggested specification: The first line of code in a stub file may be an |
That won't work for pyright and pylance. We need to determine which type stubs are applicable without loading, parsing and analyzing every type stub in the environment. This is important for language server features like completion suggestions with auto-import. A static file like |
It might be a good idea to add platform availability information to stdlib/VERSIONS, instead of using the sys.platform hack we're currently using in the source files. This has the same rationale for introducing VERSIONS in the first place:
One way to do this is an HTTP/E-Mail header-like key/value syntax:
This would allow future extension when type checkers are equipped to ignore unknown keys:
Do we need a way do indicate that a certain platform only supports a certain module starting from a certain Linux version?
The text was updated successfully, but these errors were encountered: