diff --git a/mypy/join.py b/mypy/join.py index 736e10fd20f2..4cd0da163e13 100644 --- a/mypy/join.py +++ b/mypy/join.py @@ -119,7 +119,7 @@ def visit_unbound_type(self, t: UnboundType) -> ProperType: return AnyType(TypeOfAny.special_form) def visit_union_type(self, t: UnionType) -> ProperType: - if is_subtype(self.s, t): + if is_proper_subtype(self.s, t): return t else: return mypy.typeops.make_simplified_union([self.s, t]) diff --git a/test-data/unit/check-unions.test b/test-data/unit/check-unions.test index 4fcc1007ae48..4a163136d553 100644 --- a/test-data/unit/check-unions.test +++ b/test-data/unit/check-unions.test @@ -1048,3 +1048,14 @@ def foo(a: T2, b: T2) -> T2: def bar(a: T4, b: T4) -> T4: # test multi-level alias return a + b [builtins fixtures/ops.pyi] + +[case testJoinUnionWithUnionAndAny] +# flags: --strict-optional +from typing import TypeVar, Union, Any +T = TypeVar("T") +def f(x: T, y: T) -> T: + return x +x: Union[None, Any] +y: Union[int, None] +reveal_type(f(x, y)) # N: Revealed type is 'Union[None, Any, builtins.int]' +reveal_type(f(y, x)) # N: Revealed type is 'Union[builtins.int, None, Any]'
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: