Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't simplify away Any when joining unions #9301

Merged
merged 1 commit into from
Aug 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion mypy/join.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
11 changes: 11 additions & 0 deletions test-data/unit/check-unions.test
Original file line number Diff line number Diff line change
Expand Up @@ -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]'