Skip to content

Commit 4224b93

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

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

mypy/test/testtypes.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -674,6 +674,15 @@ def callable(self, vars: list[str], *a: Type) -> CallableType:
674674
variables=tv,
675675
)
676676

677+
def test_is_type_obj_with_any_return(self) -> None:
678+
# https://github.com/python/mypy/issues/20585
679+
c = CallableType([], [], [], self.fx.anyt, self.fx.type_type)
680+
assert not c.is_type_obj()
681+
682+
def test_is_type_obj_with_instance_return(self) -> None:
683+
c = CallableType([], [], [], self.fx.a, self.fx.type_type)
684+
assert c.is_type_obj()
685+
677686

678687
class JoinSuite(Suite):
679688
def setUp(self) -> None:

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:

0 commit comments

Comments
 (0)