summaryrefslogtreecommitdiffstats
path: root/Lib/dataclasses.py
diff options
context:
space:
mode:
authoret-repositories <142979605+et-repositories@users.noreply.github.com>2024-03-19 14:58:40 (GMT)
committerGitHub <noreply@github.com>2024-03-19 14:58:40 (GMT)
commit75935746be0cbd32b9d710b93db9bd49c8d634ba (patch)
tree9d1f9c96881c97d9f2458d1cfe249f841e13f3a2 /Lib/dataclasses.py
parent3cac2af5ecfa9e2a47bfdd15e114b65780836b9d (diff)
downloadcpython-75935746be0cbd32b9d710b93db9bd49c8d634ba.zip
cpython-75935746be0cbd32b9d710b93db9bd49c8d634ba.tar.gz
cpython-75935746be0cbd32b9d710b93db9bd49c8d634ba.tar.bz2
gh-116647: Fix recursive child in dataclasses (#116790)
Diffstat (limited to 'Lib/dataclasses.py')
-rw-r--r--Lib/dataclasses.py4
1 files changed, 3 insertions, 1 deletions
diff --git a/Lib/dataclasses.py b/Lib/dataclasses.py
index e511eff..7db8a42 100644
--- a/Lib/dataclasses.py
+++ b/Lib/dataclasses.py
@@ -1075,7 +1075,9 @@ def _process_class(cls, init, repr, eq, order, unsafe_hash, frozen,
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__:',
+ body = [f'if self is other:',
+ f' return True',
+ f'if other.__class__ is self.__class__:',
f' return {field_comparisons}',
f'return NotImplemented']
func = _create_fn('__eq__',