Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
gh-116647: reverting the code
  • Loading branch information
Ethan committed Mar 15, 2024
commit c7f897f2ffe3a9632c22772a3dc98699c6c7eebb
18 changes: 7 additions & 11 deletions Lib/dataclasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -1072,17 +1072,13 @@ def _process_class(cls, init, repr, eq, order, unsafe_hash, frozen,
if eq:
# Create __eq__ method. There's no need for a __ne__ method,
# since python will call __eq__ and negate it.
cmp_fields = (field for field in field_list if field.compare)
terms = [f'(self.{field.name},)==(other.{field.name},)' for field in cmp_fields]
field_comparisons = ' and '.join(terms) or 'True'
body = [f'if other.__class__ is self.__class__:',
f' return {field_comparisons}',
f'return NotImplemented']
func = _create_fn('__eq__',
('self', 'other'),
body,
globals=globals)
_set_new_attribute(cls, '__eq__', func)
flds = [f for f in field_list if f.compare]
self_tuple = _tuple_str('self', flds)
other_tuple = _tuple_str('other', flds)
_set_new_attribute(cls, '__eq__',
_cmp_fn('__eq__', '==',
self_tuple, other_tuple,
globals=globals))

if order:
# Create and set the ordering methods.
Expand Down