Skip to content

Commit

Permalink
Make is_subtype and is_proper_subtype do promotion the same way
Browse files Browse the repository at this point in the history
Fixes #1850.
  • Loading branch information
JukkaL committed Mar 31, 2017
1 parent 29a74f3 commit 6f9ff36
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
9 changes: 5 additions & 4 deletions mypy/subtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,11 @@ def visit_instance(self, left: Instance) -> bool:
if isinstance(right, TupleType) and right.fallback.type.is_enum:
return is_subtype(left, right.fallback)
if isinstance(right, Instance):
if left.type._promote and is_subtype(
left.type._promote, self.right, self.check_type_parameter,
ignore_pos_arg_names=self.ignore_pos_arg_names):
return True
for base in left.type.mro:
if base._promote and is_subtype(
base._promote, self.right, self.check_type_parameter,
ignore_pos_arg_names=self.ignore_pos_arg_names):
return True
rname = right.type.fullname()
if not left.type.has_base(rname) and rname != 'builtins.object':
return False
Expand Down
8 changes: 8 additions & 0 deletions test-data/unit/check-unions.test
Original file line number Diff line number Diff line change
Expand Up @@ -436,3 +436,11 @@ class D:
def __le__(self, other) -> int: ...
class E:
def __ge__(self, other: Union[C, D]) -> int: ...

[case testUnionSimplificationWithBoolIntAndFloat]
from typing import List, Union
l = reveal_type([]) # type: List[Union[bool, int, float]] \
# E: Revealed type is 'builtins.list[builtins.float]'
reveal_type(l) \
# E: Revealed type is 'builtins.list[Union[builtins.bool, builtins.int, builtins.float]]'
[builtins fixtures/list.pyi]
3 changes: 2 additions & 1 deletion test-data/unit/fixtures/list.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ class list(Iterable[T], Generic[T]):
class tuple: pass
class function: pass
class int: pass
class float: pass
class str: pass
class bool: pass
class bool(int): pass

property = object() # Dummy definition.

0 comments on commit 6f9ff36

Please sign in to comment.