10000 Add flag to prohibit equality checks between non-overlapping checks by ilevkivskyi · Pull Request #6370 · python/mypy · GitHub
[go: up one dir, main page]

Skip to content

Add flag to prohibit equality checks between non-overlapping checks #6370

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

Merged
merged 13 commits into from
Feb 15, 2019
Prev Previous commit
Next Next commit
Fix lint and remaining fixture
  • Loading branch information
ilevkivskyi committed Feb 10, 2019
commit 400ac32eca8a8753790edc8e1a3d6d826cfb1b5d
8 changes: 4 additions & 4 deletions mypy/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -3010,10 +3010,10 @@ def analyze_container_item_type(self, typ: Type) -> Optional[Type]:
types.append(c_type)
return UnionType.make_union(types)
if isinstance(typ, Instance) and typ.type.has_base('typing.Container'):
supertype = self.named_type('typing.Container').type
super_instance = map_instance_to_supertype(typ, supertype)
assert len(super_instance.args) == 1
return super_instance.args[0]
supertype = self.named_type('typing.Container').type
super_instance = map_instance_to_supertype(typ, supertype)
assert len(super_instance.args) == 1
return super_instance.args[0]
return None

def analyze_index_variables(self, index: Expression, item_type: Type,
Expand Down
8 changes: 3 additions & 5 deletions test-data/unit/check-expressions.test
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ class A:
def __cmp__(self, o):
# type: ('B') -> bool
pass
def __eq__(self, o): # type: ignore
def __eq__(self, o):
# type: ('int') -> bool
pass
class B:
Expand All @@ -504,7 +504,7 @@ class C:
def __cmp__(self, o):
# type: ('A') -> bool
pass
def __eq__(self, o): # type: ignore
def __eq__(self, o):
# type: ('int') -> bool
pass

Expand Down Expand Up @@ -2079,12 +2079,10 @@ A() == B() # E: Unsupported operand types for == ("A" and "B")

[case testCustomContainsCheckStrictEquality]
# flags: --strict-equality
from typing import Container
class A:
def __contains__(self, other: A) -> bool: # type: ignore
def __contains__(self, other: A) -> bool:
...

# Don't report non-overlapping check if there is already and error.
42 in A() # E: Unsupported operand types for in ("int" and "A")
[builtins fixtures/bool.pyi]
[typing fixtures/typing-full.pyi]
6 changes: 4 additions & 2 deletions test-data/unit/fixtures/bool.pyi
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
# builtins stub used in boolean-related test cases.
from typing import Generic, TypeVar
import sys
T = TypeVar('T')

class object:
def __init__(self) -> None: pass
def __eq__(self, other: object) -> bool: pass
def __ne__(self, other: object) -> bool: pass
if sys.version_info[0] >= 3: # type: ignore
def __eq__(self, other: object) -> bool: pass
def __ne__(self, other: object) -> bool: pass

class type: pass
class tuple(Generic[T]): pass
Expand Down
0