Skip to content

Commit 907f07b

Browse files
committed
Reverse subtype check, add checks for typevar
1 parent 12e9107 commit 907f07b

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

mypy/subtypes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ def visit_type_type(self, left: TypeType) -> bool:
288288
# treat builtins.object the same as Any.
289289
return True
290290
item = left.item
291-
return isinstance(item, Instance) and is_subtype(item, right.type.metaclass_type)
291+
return isinstance(item, Instance) and is_subtype(item.type.metaclass_type, right)
292292
return False
293293

294294

test-data/unit/check-classes.test

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3137,3 +3137,12 @@ class M(type):
31373137
class A(metaclass=M): pass
31383138
reveal_type(type(A).x) # E: Revealed type is 'builtins.int'
31393139

3140+
[case testMetaclassSubtype]
3141+
from typing import Type
3142+
3143+
class M(type): pass
3144+
class A(metaclass=M): pass
3145+
3146+
a: Type[A] = A
3147+
m: M = a
3148+
m2: M = A

0 commit comments

Comments
 (0)