-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Import of Protocol is broken aftre form typing import * #4427
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
This happens because the typing stub exposes a So another example is that
passes mypy even though it will fail to run because Protocol is undefined. From reading #452, this can be solved by renaming An alternative solution might be importing |
It also appears in several other places, so it will be hard to rename all of them. In addition, this is kind of intentional, as a first step of moving |
What is the correct workaround to this problem? I'm doing this now: from typing import *
from typing_extensions import Protocol #type: ignore |
Not using star imports is the best way. Also from typing import *
if not TYPE_CHECKING:
from typing_extensions import Protocol |
Is there a way to avoid this error when writing something like the follow? # Protocol is only available in Python 3.8+.
try:
from typing import Protocol
except ImportError:
from typing_extensions import Protocol |
@GPHemsley I wrote that exact same snippet of code and landed on this page trying to fix the resulting typing error. I'm going to unstick myself by simply adding |
@GPHemsley @eblume does using |
@ethanhs |
See current issue in mypy python/mypy#4427 (comment)
As @eblume intimated, this seems to be forward compatible AND eliminates the error message:
I did not put the Hopefully someone will find this explicit example helpful. |
For all the random people landing up on this issue:
As for the original issue, closing as won't fix. This doesn't happen often, it's tricky to fix the lie in typeshed, the problem will go away on its own next year |
This code:
leads to a weird error:
The text was updated successfully, but these errors were encountered: