-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Inconsistent inference inside print() #6017
Labels
bug
mypy got something wrong
false-positive
mypy gave an error on correct code
priority-1-normal
topic-disallow-any
The disallow-any-* family of flags
Comments
Yeah, |
ilevkivskyi
added
bug
mypy got something wrong
priority-1-normal
false-positive
mypy gave an error on correct code
labels
Dec 5, 2018
Append to the false-positive stack, please: import typing as ty
class ChildAddress(ty.Tuple[int, int]):
"""Represents MIDI (Bus, Channel) of child Track.
Can be compared to tuple. All (busses/channels) are equal to one.
"""
def __new__(cls, bus: int, channel: int) -> 'ChildAddress':
return super().__new__(cls, (bus, channel))
# Argument 2 to "__new__" of "tuple" has incompatible type "Tuple[int, int]"; expected "Iterable[_T_co]"
def __init__(self, bus: int, channel: int) -> None:
"""make immutable address.
Parameters
----------
bus : int
channel : int
"""
super().__init__()
@property
def bus(self) -> int:
"""MIDI Bus.
Returns
-------
int
0 if All buses
-1 if no midi routing
"""
return self[0]
@property
def channel(self) -> int:
"""Midi Channel.
Returns
-------
int
0 if All channels
-1 if no midi routing
"""
return self[1]
def __eq__(self, other: object) -> bool:
if not isinstance(other, ty.Sequence):
return False
if len(other) != 2:
return False
for item in other:
if not isinstance(item, int):
return False
if item > 16:
return False
other = ty.cast(ty.Tuple[int, int], other)
if other[0] != self[0]:
for item in ty.cast(ty.Tuple[int, int], (other[0], self[0])):
# Redundant cast to "Tuple[int, int]"
if item != '0': # Expression has type "Any"
return False
else:
break
if other[1] != self[1]:
for item in (other[1], self[1]):
if item != 0: # Expression has type "Any"
return False
else:
break
return True
def __repr__(self) -> str:
return f'ChildAddress(bus={self.bus}, channel={self.channel})'
def __hash__(self) -> int:
return hash((self[0], self[1])) |
The false-positive error is no longer emitted on mypy 0.700+ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
bug
mypy got something wrong
false-positive
mypy gave an error on correct code
priority-1-normal
topic-disallow-any
The disallow-any-* family of flags
Just found that mypy infers the type of
sum(l)
in the code below differently depending on whether it is inside aprint()
:Tested with mypy 0.641 and 0.650+dev.ad2d4ba1db9699779d5705094f991d3bb3ac112d (current master branch) on Python 3.7.1, results are same.
The text was updated successfully, but these errors were encountered: