|
8 | 8 | from mypy.erasetype import erase_type, remove_instance_last_known_values |
9 | 9 | from mypy.indirection import TypeIndirectionVisitor |
10 | 10 | from mypy.join import join_types |
11 | | -from mypy.meet import meet_types, narrow_declared_type |
| 11 | +from mypy.meet import is_overlapping_types, meet_types, narrow_declared_type |
12 | 12 | from mypy.nodes import ( |
13 | 13 | ARG_NAMED, |
14 | 14 | ARG_OPT, |
@@ -645,6 +645,20 @@ def assert_simplified_union(self, original: list[Type], union: Type) -> None: |
645 | 645 | assert_equal(make_simplified_union(original), union) |
646 | 646 | assert_equal(make_simplified_union(list(reversed(original))), union) |
647 | 647 |
|
| 648 | + def test_generic_callable_overlap_is_symmetric(self) -> None: |
| 649 | + any_type = AnyType(TypeOfAny.from_omitted_generics) |
| 650 | + outer_t = TypeVarType("T", "T", TypeVarId(1), [], self.fx.o, any_type) |
| 651 | + outer_s = TypeVarType("S", "S", TypeVarId(2), [], self.fx.o, any_type) |
| 652 | + generic_t = TypeVarType("T", "T", TypeVarId(-1), [], self.fx.o, any_type) |
| 653 | + |
| 654 | + callable_type = CallableType([outer_t], [ARG_POS], [None], outer_s, self.fx.function) |
| 655 | + generic_identity = CallableType( |
| 656 | + [generic_t], [ARG_POS], [None], generic_t, self.fx.function, variables=[generic_t] |
| 657 | + ) |
| 658 | + |
| 659 | + assert is_overlapping_types(callable_type, generic_identity) |
| 660 | + assert is_overlapping_types(generic_identity, callable_type) |
| 661 | + |
648 | 662 | # Helpers |
649 | 663 |
|
650 | 664 | def tuple(self, *a: Type) -> TupleType: |
|
0 commit comments