Skip to content

Commit c0fcad8

Browse files
committed
Fix crash when calling type[Any] from dict.get()
1 parent 131f9d9 commit c0fcad8

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

mypy/types.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2331,7 +2331,7 @@ def is_kw_arg(self) -> bool:
23312331

23322332
def is_type_obj(self) -> bool:
23332333
return self.fallback.type.is_metaclass() and not isinstance(
2334-
get_proper_type(self.ret_type), UninhabitedType
2334+
get_proper_type(self.ret_type), (UninhabitedType, AnyType)
23352335
)
23362336

23372337
def type_object(self) -> mypy.nodes.TypeInfo:

test-data/unit/check-classes.test

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9398,3 +9398,10 @@ from typ import NT
93989398
def f() -> NT:
93999399
return NT(x='')
94009400
[builtins fixtures/tuple.pyi]
9401+
9402+
[case testCallingTypeAnyDoesNotCrash]
9403+
# Regression test for https://github.com/python/mypy/issues/20585
9404+
from typing import Any
9405+
op: type[Any]
9406+
reveal_type({0: object}.get(0, op)()) # N: Revealed type is "builtins.object"
9407+
[builtins fixtures/dict.pyi]

0 commit comments

Comments
 (0)