Skip to content

Don't crash on reversible dunder methods with extra arguments #5348

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 2 commits into from
Jul 13, 2018
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/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -1003,7 +1003,7 @@ def check_reverse_op_method(self, defn: FuncItem,
reverse_type = reverse_type.copy_modified(arg_types=[reverse_type.arg_types[0]] * 2,
arg_kinds=[ARG_POS] * 2,
arg_names=[reverse_type.arg_names[0], "_"])
assert len(reverse_type.arg_types) == 2
assert len(reverse_type.arg_types) >= 2

forward_name = nodes.normal_from_reverse_op[reverse_name]
forward_inst = reverse_type.arg_types[1]
Expand Down
4 changes: 4 additions & 0 deletions test-data/unit/check-expressions.test
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,10 @@ s = A() < B()
n = A() < B() # E: Incompatible types in assignment (expression has type "str", variable has type "int")
s = object() < B() # E: Unsupported operand types for > ("B" and "object")

[case testReversibleComparisonWithExtraArgument]
class C:
def __lt__(self, o: object, x: str = "") -> int: ...

[case testErrorContextAndBinaryOperators]
import typing
class A:
Expand Down