-
-
Notifications
You must be signed in to change notification settings - Fork 2.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
Possible regression in mypy 0.981: Generics don't work when TypeVar are previously used in a TypedDict #13755
Comments
Reproduced: https://mypy-play.net/?mypy=latest&python=3.10&gist=f60adc581fff2b54cb71c860ada20577 @ilevkivskyi, one for you? :) |
Another example that may originate from the same issue. Commenting from typing import Sequence, TypeVar
from typing_extensions import TypedDict
T = TypeVar("T")
MyDict1 = TypedDict("MyDict1", {"foo": Sequence[T]})
MyDict2 = TypedDict("MyDict2", {"foo": Sequence[T]})
MyDict1[int] # ok
MyDict2[int] # mypy(error): The type "Type[MyDict2]" is not generic and not indexable [misc] |
This is not really a regression, as previously you would still get an error (in a different place). It is however indeed a bug, you should be able to reuse the type variable. Unless I am missing something, should be a simple fix. |
Oh, actually both examples work correctly on master. It looks like @Michael0x2a already added the missing TypeVar scope frame in #13678 (and also fixed a docstring for me, thank you!) |
(btw it was one of rare cases where |
This is a small follow-up to python#13678 and python#13755. In the former diff, I added a TypeVar scope frame around TypedDict creation. However, I had really no good reason for doing this at the time: I wasn't able to find a bug due to the missing frame and added it purely speculatively, out of a desire for symmetry. It turns out this missing frame does legitimately cause some issues, which were reported in the latter. So, this diff encodes one of the reported bugs as a test case to make sure we don't regress.
This is a small follow-up to #13678 and #13755. In the former diff, I added a TypeVar scope frame around TypedDict creation. However, I had really no good reason for doing this at the time: I wasn't able to find a bug due to the missing frame and added it purely speculatively, out of a desire for symmetry. It turns out this missing frame does legitimately cause some issues, which were reported in the latter. So, this diff encodes one of the reported bugs as a test case to make sure we don't regress.
Bug Report
When pulling the example of Generics from the documentation and specifying a generic TypedDict following the blog post, I get an error on simple Generic example.
To Reproduce
Commenting line 5 removes the error. Moving line 5 after the declaration of
Stack
also works.Expected Behavior
That class Stack is a correct Generic and mypy should not error.
Your Environment
The text was updated successfully, but these errors were encountered: