Skip to content

Allow nesting of Annotated with TypedDict special forms inside TypedDicts #18165

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion mypy/typeanal.py
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,9 @@ def try_analyze_special_unbound_type(self, t: UnboundType, fullname: str) -> Typ
code=codes.VALID_TYPE,
)
return AnyType(TypeOfAny.from_error)
return self.anal_type(t.args[0])
return self.anal_type(
t.args[0], allow_typed_dict_special_forms=self.allow_typed_dict_special_forms
)
elif fullname in ("typing_extensions.Required", "typing.Required"):
if not self.allow_typed_dict_special_forms:
self.fail(
Expand Down
10 changes: 10 additions & 0 deletions test-data/unit/check-typeddict.test
Original file line number Diff line number Diff line change
Expand Up @@ -3989,6 +3989,16 @@ class TP(TypedDict):
[builtins fixtures/dict.pyi]
[typing fixtures/typing-typeddict.pyi]

[case testTypedDictAnnotatedWithSpecialForms]
from typing import NotRequired, ReadOnly, Required, TypedDict
from typing_extensions import Annotated

class A(TypedDict):
a: Annotated[NotRequired[ReadOnly[int]], ""] # ok
b: NotRequired[ReadOnly[Annotated[int, ""]]] # ok
[builtins fixtures/dict.pyi]
[typing fixtures/typing-typeddict.pyi]

[case testTypedDictReadOnlyCovariant]
from typing import ReadOnly, TypedDict, Union

Expand Down
Loading