Skip to content
Snippets Groups Projects
Commit 1378c420 authored by Andreas Klöckner's avatar Andreas Klöckner Committed by Andreas Klöckner
Browse files

with_container_arithmetic: Nix implementation of __eq__ if eq_comparison not requested

parent ce936a7a
No related branches found
No related tags found
No related merge requests found
......@@ -304,12 +304,25 @@ def with_container_arithmetic(
# {{{ binary operators
for dunder_name, op_str, reversible, op_cls in _BINARY_OP_AND_DUNDER:
fname = f"_{cls.__name__.lower()}_{dunder_name}"
if op_cls not in desired_op_classes:
# Leaving equality comparison at the default supplied by
# dataclasses is dangerous: Comparison of dataclass fields
# might return an array of truth values, and the dataclasses
# implementation of __eq__ might consider that 'truthy' enough,
# yielding bogus equality results.
if op_cls == _OpClass.EQ_COMPARISON:
gen(f"def {fname}(arg1, arg2):")
with Indentation(gen):
gen("return NotImplemented")
gen(f"cls.__{dunder_name}__ = {fname}")
gen("")
continue
# {{{ "forward" binary operators
fname = f"_{cls.__name__.lower()}_{dunder_name}"
zip_init_args = cls._deserialize_init_arrays_code("arg1", {
same_key(key_arg1, key_arg2):
_format_binary_op_str(op_str, expr_arg1, expr_arg2)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment