-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
No Generator is considered to be an instance of GeneratorType #5496
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
You're in luck because I just submitted a typeshed PR that should fix this: #5474. |
Thanks! I'm trying to verify that your PR fixes this, but I can't get mypy to use an external typeshed directory:
Where |
You may have to also use mypy master. mypy hasn't had a release yet since we changed the typeshed directory structure a few months ago. |
Indeed it works with mypy master and the unexpected errors are gone then. Should I close this issue now or wait until the fix has been merged? |
I'll transfer the issue to typeshed and associate the PR with the issue. |
Also, thanks for checking! |
OK, and thanks for fixing this before I even reported it. |
Bug Report
types.GeneratorType
is documented as "The type of generator-iterator objects, created by generator functions." Therefore I would expect that a value annotated usingtyping.Generator
would be considered an instance ofGeneratorType
. However, that is not the case.It is possible that this issue originates in typeshed instead of mypy; I don't know whether mypy is drawing the wrong conclusions or is operating on flawed definitions. Even if the problem is in typeshed, perhaps mypy can output a more detailed error message, listing which method signatures it considers incompatible.
To Reproduce
Run mypy on the following code:
Expected Behavior
Only
check(None)
should be flagged as an error.Actual Behavior
The first error (
isinstance
), reported on line 5, is the one I consider a bug.The error reported on line 7 (
print
) is a consequence of the one on line 5.The error reported on line 15 (
check(None)
) is an actual error.Note that the runtime behavior is as expected:
Your Environment
I'm using mypy 0.812 with Python 3.8.8 on openSUSE Linux.
The text was updated successfully, but these errors were encountered: