Skip to content

Commit 053ff27

Browse files
authored
Add test case for missing TypedDict TypeVar scope frame (#13764)
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.
1 parent efdda88 commit 053ff27

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

‎test-data/unit/check-typeddict.test‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2545,6 +2545,22 @@ Alias(key=0, value=0) # E: Missing type parameters for generic type "Alias" \
25452545
[builtins fixtures/dict.pyi]
25462546
[typing fixtures/typing-typeddict.pyi]
25472547

2548+
[case testGenericTypedDictMultipleGenerics]
2549+
# See https://github.com/python/mypy/issues/13755
2550+
from typing import Generic, TypeVar, TypedDict
2551+
2552+
T = TypeVar("T")
2553+
Foo = TypedDict("Foo", {"bar": T})
2554+
class Stack(Generic[T]): pass
2555+
2556+
a = Foo[str]
2557+
b = Foo[int]
2558+
reveal_type(a) # N: Revealed type is "def (*, bar: builtins.str) -> TypedDict('__main__.Foo', {'bar': builtins.str})"
2559+
reveal_type(b) # N: Revealed type is "def (*, bar: builtins.int) -> TypedDict('__main__.Foo', {'bar': builtins.int})"
2560+
2561+
[builtins fixtures/dict.pyi]
2562+
[typing fixtures/typing-typeddict.pyi]
2563+
25482564
[case testGenericTypedDictCallSyntax]
25492565
from typing import TypedDict, TypeVar
25502566

0 commit comments

Comments
 (0)