Skip to content
Open
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 mypyc/irbuild/classdef.py
Original file line number Diff line number Diff line change
Expand Up @@ -867,7 +867,7 @@ def gen_glue_ne_method(builder: IRBuilder, cls: ClassIR, line: int) -> None:
eq_sig = func_ir.decl.sig
strict_typing = builder.options.strict_dunders_typing
with builder.enter_method(cls, "__ne__", eq_sig.ret_type):
rhs_type = eq_sig.args[0].type if strict_typing else object_rprimitive
rhs_type = eq_sig.args[1].type if strict_typing else object_rprimitive
rhs_arg = builder.add_argument("rhs", rhs_type)
eqval = builder.add(MethodCall(builder.self(), "__eq__", [rhs_arg], line))

Expand Down
12 changes: 12 additions & 0 deletions mypyc/test-data/run-dunders.test
Original file line number Diff line number Diff line change
Expand Up @@ -1009,3 +1009,15 @@ def test_equality_with_implicit_ne() -> None:
assert not eq(Eq(1), Eq(2))
assert ne(Eq(1), Eq(2))
assert not ne(Eq(1), Eq(1))

[case testDundersImplicitNeWithNarrowRhs]
class Accepted:
pass

class Eq:
def __eq__(self, other: Accepted) -> bool: # type: ignore[override]
return True

def test_implicit_ne_with_narrow_rhs() -> None:
assert Eq() == Accepted()
assert not (Eq() != Accepted())
Loading