Skip to content

Commit 1eecf2a

Browse files
committed
add comments
1 parent 0a98d68 commit 1eecf2a

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

Lib/dataclasses.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -434,12 +434,12 @@ def _tuple_str(obj_name, fields):
434434

435435

436436
def _tuple_compare_expand(op, fields):
437-
op_without_eq = op[0]
438-
op_has_eq = op[-1] == "="
439437
for f in fields:
440438
yield f' if self.{f.name} != other.{f.name}:'
441-
yield f' return self.{f.name} {op_without_eq} other.{f.name}'
442-
yield f' return {op_has_eq}'
439+
# ? use "op[0]" here since gated by "!=", probably not worth it
440+
yield f' return self.{f.name} {op} other.{f.name}'
441+
# the instances are equal here, return constant
442+
yield f' return {op.endswith("=")}'
443443

444444

445445
class _FuncBuilder:
@@ -1145,10 +1145,12 @@ def _process_class(cls, init, repr, eq, order, unsafe_hash, frozen,
11451145
# Create a comparison function. If the fields in the object are
11461146
# named 'x' and 'y'.
11471147
# if self.x != other.x:
1148-
# return self.x {op[0]} other.x
1148+
# return self.x {op} other.x
11491149
# if self.y != other.y:
1150-
# return self.y {op[0]} other.y
1150+
# return self.y {op} other.y
11511151
# return {op.endswith("=")}
1152+
1153+
# __eq__ has this self guard, add here for consistency
11521154
self_guard = [' if self is other:', ' return True'] if op.endswith("=") else []
11531155
func_builder.add_fn(name,
11541156
('self', 'other'),

0 commit comments

Comments
 (0)