Skip to content

Commit 0432c2a

Browse files
committed
normalize
1 parent 69bf114 commit 0432c2a

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

Lib/dataclasses.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -436,13 +436,11 @@ def _tuple_str(obj_name, fields):
436436
def _tuple_compare_expand(op, fields):
437437
if fields:
438438
for f in fields[:-1]:
439-
yield (
440-
f' if self.{f.name} != other.{f.name}:\n'
441-
f' return self.{f.name} {op} other.{f.name}'
442-
)
443-
yield f' return self.{fields[-1].name} {op} other.{fields[-1].name}'
439+
yield f' if self.{f.name} != other.{f.name}:'
440+
yield f' return self.{f.name} {op} other.{f.name}'
441+
yield f' return self.{fields[-1].name} {op} other.{fields[-1].name}'
444442
else:
445-
yield f' return {op.endswith("=")}'
443+
yield f' return {op.endswith("=")}'
446444

447445

448446
class _FuncBuilder:
@@ -1148,11 +1146,13 @@ def _process_class(cls, init, repr, eq, order, unsafe_hash, frozen,
11481146
# Create a comparison function. If the fields in the object are
11491147
# named 'x' and 'y'.
11501148
# if self.x != other.x:
1151-
# return self.x {op} other.x
1149+
# return self.x {op} other.x
11521150
# return self.y {op} other.y
1151+
self_guard = [' if self is other:', ' return True'] if op.endswith("=") else []
11531152
func_builder.add_fn(name,
11541153
('self', 'other'),
1155-
[ ' if other.__class__ is self.__class__:',
1154+
[*self_guard,
1155+
' if other.__class__ is self.__class__:',
11561156
*_tuple_compare_expand(op, flds),
11571157
' return NotImplemented'],
11581158
overwrite_error='Consider using functools.total_ordering')

0 commit comments

Comments
 (0)