From 2debb8652731550df9aec39e60d87cc40972a791 Mon Sep 17 00:00:00 2001 From: Shantanu Jain Date: Sun, 25 May 2025 19:19:16 -0700 Subject: [PATCH] Fix commutativity of join between TypeType and TypeVar Fixes #18125 --- mypy/join.py | 2 ++ mypy/test/testtypes.py | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/mypy/join.py b/mypy/join.py index ac01d11d11d6..fcfc6cbaa0e7 100644 --- a/mypy/join.py +++ b/mypy/join.py @@ -635,6 +635,8 @@ def default(self, typ: Type) -> ProperType: typ = get_proper_type(typ) if isinstance(typ, Instance): return object_from_instance(typ) + elif isinstance(typ, TypeType): + return self.default(typ.item) elif isinstance(typ, UnboundType): return AnyType(TypeOfAny.special_form) elif isinstance(typ, TupleType): diff --git a/mypy/test/testtypes.py b/mypy/test/testtypes.py index a42519c64956..63d8840fa217 100644 --- a/mypy/test/testtypes.py +++ b/mypy/test/testtypes.py @@ -1064,6 +1064,10 @@ def test_variadic_tuple_joins(self) -> None: self.tuple(UnpackType(Instance(self.fx.std_tuplei, [self.fx.a])), self.fx.a), ) + def test_join_type_type_type_var(self) -> None: + self.assert_join(self.fx.type_a, self.fx.t, self.fx.o) + self.assert_join(self.fx.t, self.fx.type_a, self.fx.o) + # There are additional test cases in check-inference.test. # TODO: Function types + varargs and default args.