Skip to content

Commit ec6dc1b

Browse files
committed
Allow TypedDict special forms inside Annotated
1 parent 8ef2197 commit ec6dc1b

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

mypy/typeanal.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -688,7 +688,9 @@ def try_analyze_special_unbound_type(self, t: UnboundType, fullname: str) -> Typ
688688
code=codes.VALID_TYPE,
689689
)
690690
return AnyType(TypeOfAny.from_error)
691-
return self.anal_type(t.args[0])
691+
return self.anal_type(
692+
t.args[0], allow_typed_dict_special_forms=self.allow_typed_dict_special_forms
693+
)
692694
elif fullname in ("typing_extensions.Required", "typing.Required"):
693695
if not self.allow_typed_dict_special_forms:
694696
self.fail(

test-data/unit/check-typeddict.test

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3989,6 +3989,15 @@ class TP(TypedDict):
39893989
[builtins fixtures/dict.pyi]
39903990
[typing fixtures/typing-typeddict.pyi]
39913991

3992+
[case testTypedDictAnnotatedWithSpecialForms]
3993+
from typing import NotRequired, ReadOnly, Required, TypedDict
3994+
3995+
class A(TypedDict):
3996+
a: Annotated[NotRequired[ReadOnly[int]], ""] # ok
3997+
b: NotRequired[ReadOnly[Annotated[int, ""]]] # ok
3998+
[builtins fixtures/dict.pyi]
3999+
[typing fixtures/typing-typeddict.pyi]
4000+
39924001
[case testTypedDictReadOnlyCovariant]
39934002
from typing import ReadOnly, TypedDict, Union
39944003

0 commit comments

Comments
 (0)