Skip to content
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

Support importing ParamSpec and Concatenate from typing_extensions (PEP 612) #1276

Closed
gvanrossum opened this issue Dec 14, 2020 · 4 comments
Closed
Labels
addressed in next version Issue is fixed and will appear in next published version enhancement request New feature or request

Comments

@gvanrossum
Copy link

I've just introduced ParamSpec and Concatenate in typing_extensions.pyi in typeshed.

I'd like code that uses

from typing_extensions import ParamSpec, Concatenate

to work in all Python versions (not just in 3.10).

The real typing_extensions distro will be updated soon.

@erictraut
Copy link
Collaborator

erictraut commented Dec 14, 2020

I pulled the latest typeshed stubs into the pyright repo, and they will be included in the next release.

This change doesn't require any code changes to the type checker logic, so if you want to try it out in the meantime, you can manually update your local copy of typing_extensions.pyi that ships with pyright or pylance. Just select typing_extensions in the import statement and press F12 to display it in VS Code, then copy in the additional lines that define ParamSpec and Concatenate.

@erictraut erictraut added addressed in next version Issue is fixed and will appear in next published version enhancement request New feature or request labels Dec 14, 2020
@gvanrossum
Copy link
Author

Thanks that works. Does it work without pyright changes because you anticipated this, or because of some other magic? I.e. if I put ParamSpec in foo.pyi and type from foo import ParamSpec would that also have the same semantics?

Either way you can close this issue.

@erictraut
Copy link
Collaborator

It's because of the way that pyright recognizes special built-in types — those that require special handling within the type checker (like "Tuple", "TypeVar" and "ParamSpec"). Pyright designates a small subset of modules (builtins.pyi, typing.pyi and typing_extensions.pyi) as "modules that define special built-in types". It accommodates the possibility that these special types could be declared in any of these special modules. It doesn't care whether it finds "ParamSpec" declared in typing.pyi or typing_extensions.pyi. It treats them the same. This simplifies the code and accommodates more flexibility in cases like this one.

I'll close the issue once we release the next version of pyright with the updated typeshed stubs.

@erictraut
Copy link
Collaborator

erictraut commented Dec 23, 2020

This is now addressed in Pyright 1.1.96, which I just published. It will also be in the next published release of Pylance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
addressed in next version Issue is fixed and will appear in next published version enhancement request New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants