Skip to content

Remove the 'rop will not be called' error message #5571

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
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
11 changes: 0 additions & 11 deletions mypy/checkexpr.py
Original file line number Diff line number Diff line change
Expand Up @@ -1909,7 +1909,6 @@ def lookup_definer(typ: Instance, attr_name: str) -> Optional[str]:
# We store the determined order inside the 'variants_raw' variable,
# which records tuples containing the method, base type, and the argument.

warn_about_uncalled_reverse_operator = False
bias_right = is_proper_subtype(right_type, left_type)
if op_name in nodes.op_methods_that_shortcut and is_same_type(left_type, right_type):
# When we do "A() + A()", for example, Python will only call the __add__ method,
Expand All @@ -1921,8 +1920,6 @@ def lookup_definer(typ: Instance, attr_name: str) -> Optional[str]:
variants_raw = [
(left_op, left_type, right_expr)
]
if right_op is not None:
warn_about_uncalled_reverse_operator = True
elif (is_subtype(right_type, left_type)
and isinstance(left_type, Instance)
and isinstance(right_type, Instance)
Expand Down Expand Up @@ -2010,14 +2007,6 @@ def lookup_definer(typ: Instance, attr_name: str) -> Optional[str]:
return result

self.msg.add_errors(errors[0])
if warn_about_uncalled_reverse_operator:
self.msg.reverse_operator_method_never_called(
nodes.op_methods_to_symbols[op_name],
op_name,
right_type,
rev_op_name,
context,
)
if len(results) == 1:
return results[0]
else:
Expand Down
16 changes: 0 additions & 16 deletions mypy/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -1003,22 +1003,6 @@ def overloaded_signatures_ret_specific(self, index: int, context: Context) -> No
self.fail('Overloaded function implementation cannot produce return type '
'of signature {}'.format(index), context)

def reverse_operator_method_never_called(self,
op: str,
forward_method: str,
reverse_type: Type,
reverse_method: str,
context: Context) -> None:
msg = "{rfunc} will not be called when evaluating '{cls} {op} {cls}': must define {ffunc}"
self.note(
msg.format(
op=op,
ffunc=forward_method,
rfunc=reverse_method,
cls=self.format_bare(reverse_type),
),
context=context)

def operator_method_signatures_overlap(
self, reverse_class: TypeInfo, reverse_method: str, forward_class: Type,
forward_method: str, context: Context) -> None:
Expand Down
9 changes: 3 additions & 6 deletions test-data/unit/check-classes.test
Original file line number Diff line number Diff line change
Expand Up @@ -1616,8 +1616,7 @@ class B(A): pass
# Note: This is a runtime error. If we run x.__add__(y)
# where x and y are *not* the same type, Python will not try
# calling __radd__.
A() + A() # E: Unsupported operand types for + ("A" and "A") \
# N: __radd__ will not be called when evaluating 'A + A': must define __add__
A() + A() # E: Unsupported operand types for + ("A" and "A")

# Here, Python *will* call __radd__(...)
reveal_type(B() + A()) # E: Revealed type is '__main__.A'
Expand Down Expand Up @@ -1733,8 +1732,7 @@ class A:
def __radd__(self, other: 'A') -> int: ...

# Note: Python only tries calling __add__ and never __radd__, even though it's present
A() + A() # E: Unsupported left operand type for + ("A") \
# N: __radd__ will not be called when evaluating 'A + A': must define __add__
A() + A() # E: Unsupported left operand type for + ("A")

[case testReverseOperatorOrderingCase2]
class A:
Expand Down Expand Up @@ -2006,8 +2004,7 @@ reveal_type(FractionChild() + FractionChild()) # E: Revealed type is 'builtins.

# Runtime error: we try calling __add__, it doesn't match, and we don't try __radd__ since
# the LHS and the RHS are not the same.
Fraction() + Fraction() # E: Unsupported operand types for + ("Fraction" and "Fraction") \
# N: __radd__ will not be called when evaluating 'Fraction + Fraction': must define __add__
Fraction() + Fraction() # E: Unsupported operand types for + ("Fraction" and "Fraction")

[case testReverseOperatorTypeType]
from typing import TypeVar, Type
Expand Down