Skip to content

Commit 2debb86

Browse files
committed
Fix commutativity of join between TypeType and TypeVar
Fixes python#18125
1 parent a8ec893 commit 2debb86

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

mypy/join.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -635,6 +635,8 @@ def default(self, typ: Type) -> ProperType:
635635
typ = get_proper_type(typ)
636636
if isinstance(typ, Instance):
637637
return object_from_instance(typ)
638+
elif isinstance(typ, TypeType):
639+
return self.default(typ.item)
638640
elif isinstance(typ, UnboundType):
639641
return AnyType(TypeOfAny.special_form)
640642
elif isinstance(typ, TupleType):

mypy/test/testtypes.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1064,6 +1064,10 @@ def test_variadic_tuple_joins(self) -> None:
10641064
self.tuple(UnpackType(Instance(self.fx.std_tuplei, [self.fx.a])), self.fx.a),
10651065
)
10661066

1067+
def test_join_type_type_type_var(self) -> None:
1068+
self.assert_join(self.fx.type_a, self.fx.t, self.fx.o)
1069+
self.assert_join(self.fx.t, self.fx.type_a, self.fx.o)
1070+
10671071
# There are additional test cases in check-inference.test.
10681072

10691073
# TODO: Function types + varargs and default args.

0 commit comments

Comments
 (0)