@@ -116,6 +116,10 @@ def {method}(self) -> Self:
116
116
template_other_unary = """
117
117
def {method}(self, *args: Any, **kwargs: Any) -> Self:
118
118
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]"""
119
123
120
124
# For some methods we override return type `bool` defined by base class `object`.
121
125
# We need to add "# type: ignore[override]"
@@ -152,6 +156,7 @@ def binops(
152
156
template_binop ,
153
157
extras | {"type_ignore" : _type_ignore (type_ignore_eq )},
154
158
),
159
+ ([(None , None )], unhashable , extras ),
155
160
(BINOPS_REFLEXIVE , template_reflexive , extras ),
156
161
]
157
162
@@ -185,6 +190,7 @@ def binops_overload(
185
190
"overload_type_ignore" : _type_ignore (type_ignore_eq ),
186
191
},
187
192
),
193
+ ([(None , None )], unhashable , extras ),
188
194
(BINOPS_REFLEXIVE , template_reflexive , extras ),
189
195
]
190
196
0 commit comments