Skip to content

Commit d5d077b

Browse files
hmc-cs-mdrissiMehdi Drissi
and
Mehdi Drissi
authored
Fix crash involving explicit any flag and Required (#12039)
Co-authored-by: Mehdi Drissi <[email protected]>
1 parent 99f4d5a commit d5d077b

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

mypy/types.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,9 @@ def __repr__(self) -> str:
360360
else:
361361
return "NotRequired[{}]".format(self.item)
362362

363+
def accept(self, visitor: 'TypeVisitor[T]') -> T:
364+
return self.item.accept(visitor)
365+
363366

364367
class ProperType(Type):
365368
"""Not a type alias.

test-data/unit/check-typeddict.test

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2208,6 +2208,12 @@ class Movie(TypedDict, total=False):
22082208
year: int
22092209
[typing fixtures/typing-typeddict.pyi]
22102210

2211+
[case testRequiredExplicitAny]
2212+
# flags: --disallow-any-explicit
2213+
from typing import TypedDict
2214+
from typing import Required
2215+
Foo = TypedDict("Foo", {"a.x": Required[int]})
2216+
[typing fixtures/typing-typeddict.pyi]
22112217

22122218
-- NotRequired[]
22132219

@@ -2271,6 +2277,13 @@ class Movie(TypedDict):
22712277
year: int
22722278
[typing fixtures/typing-typeddict.pyi]
22732279

2280+
[case testNotRequiredExplicitAny]
2281+
# flags: --disallow-any-explicit
2282+
from typing import TypedDict
2283+
from typing import NotRequired
2284+
Foo = TypedDict("Foo", {"a.x": NotRequired[int]})
2285+
[typing fixtures/typing-typeddict.pyi]
2286+
22742287
-- Union dunders
22752288

22762289
[case testTypedDictUnionGetItem]

test-data/unit/fixtures/typing-typeddict.pyi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ class Iterator(Iterable[T_co], Protocol):
4343
def __next__(self) -> T_co: pass
4444

4545
class Sequence(Iterable[T_co]):
46-
def __getitem__(self, n: Any) -> T_co: pass
46+
# misc is for explicit Any.
47+
def __getitem__(self, n: Any) -> T_co: pass # type: ignore[misc]
4748

4849
class Mapping(Iterable[T], Generic[T, T_co], metaclass=ABCMeta):
4950
def __getitem__(self, key: T) -> T_co: pass

0 commit comments

Comments
 (0)