Skip to content

Commit a468d08

Browse files
committed
Add unhashable to generate_ops
1 parent feba698 commit a468d08

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

xarray/util/generate_ops.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,10 @@ def {method}(self) -> Self:
116116
template_other_unary = """
117117
def {method}(self, *args: Any, **kwargs: Any) -> Self:
118118
return self._unary_op({func}, *args, **kwargs)"""
119+
unhashable = """
120+
# When __eq__ is defined but __hash__ is not, then an object is unhashable,
121+
# and it should be declared as follows:
122+
__hash__: None # type:ignore[assignment]"""
119123

120124
# For some methods we override return type `bool` defined by base class `object`.
121125
# We need to add "# type: ignore[override]"
@@ -152,6 +156,7 @@ def binops(
152156
template_binop,
153157
extras | {"type_ignore": _type_ignore(type_ignore_eq)},
154158
),
159+
([(None, None)], unhashable, extras),
155160
(BINOPS_REFLEXIVE, template_reflexive, extras),
156161
]
157162

@@ -185,6 +190,7 @@ def binops_overload(
185190
"overload_type_ignore": _type_ignore(type_ignore_eq),
186191
},
187192
),
193+
([(None, None)], unhashable, extras),
188194
(BINOPS_REFLEXIVE, template_reflexive, extras),
189195
]
190196

0 commit comments

Comments
 (0)