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

Error using typing_extensions.Protocol with Python 3.6 #2987

Closed
tsibley opened this issue Feb 4, 2022 · 4 comments
Closed

Error using typing_extensions.Protocol with Python 3.6 #2987

tsibley opened this issue Feb 4, 2022 · 4 comments
Labels
addressed in next version Issue is fixed and will appear in next published version bug Something isn't working

Comments

@tsibley
Copy link

tsibley commented Feb 4, 2022

Describe the bug
pyright 1.1.217 (installed from NPM) incorrectly reports Use of "Protocol" requires Python 3.7 or newer when analyzing for Python 3.6 and importing Protocol from typing_extensions.

To Reproduce
With the code below saved in example.py, run:

$ pyright --pythonversion 3.6 example.py
No configuration file found.
No pyproject.toml file found.
stubPath /tmp/pyright-repro/typings is not a valid directory.
Assuming Python platform Linux
Searching for source files
Found 1 source file
/tmp/pyright-repro/example.py
  /tmp/pyright-repro/example.py:3:9 - error: Use of "Protocol" requires Python 3.7 or newer
1 error, 0 warnings, 0 informations
Completed in 0.597sec

$ pyright --version
pyright 1.1.217

Expected behavior
importing Protocol from typing_extensions should not trigger an error.

Screenshots or Code

from typing_extensions import Protocol

class A(Protocol):
    pass

VS Code extension or command-line
pyright 1.1.217 from NPM.

Additional context
Regression of a previously fixed bug: #763

tsibley added a commit to nextstrain/cli that referenced this issue Feb 4, 2022
It contains a regression¹ that reports errors about using Protocol from
typing_extensions on Python 3.6.  If you have pyright pre-installed
locally (instead of just-in-time installed via npx), manually downgrade
to pyright 1.1.216 to avoid spurious errors.

¹ microsoft/pyright#2987
@erictraut erictraut added the bug Something isn't working label Feb 4, 2022
@erictraut
Copy link
Collaborator

The problem here is that typing_extensions.pyi was recently changed to import the symbol Protocol from typing.pyi rather than defining its own version of the symbol. Now pyright can't tell the difference between the two because they are the same symbol. If a Python 3.6 source file imports the symbol from typing, it will result in a runtime exception, which is why the error message was added originally.

I'll need to ask the maintainers of typeshed why they made this change and see if they're willing to revert it.

@erictraut erictraut added needs decision blocked Waiting on external fix addressed in next version Issue is fixed and will appear in next published version bug Something isn't working and removed bug Something isn't working needs decision blocked Waiting on external fix labels Feb 4, 2022
@erictraut
Copy link
Collaborator

I submitted the change to the typeshed repo. It has been merged, and I updated pyright's copy of the typeshed stubs accordingly, so this will be fixed in the next release.

@erictraut
Copy link
Collaborator

This is addressed in pyright 1.1.219, which I just published. It will also be in the next release of pylance.

@tsibley
Copy link
Author

tsibley commented Feb 7, 2022

@erictraut Thank you!

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 bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants