summaryrefslogtreecommitdiffstats
path: root/Lib/dataclasses.py
diff options
context:
space:
mode:
authorNikita Sobolev <mail@sobolevn.me>2024-03-05 18:12:00 (GMT)
committerGitHub <noreply@github.com>2024-03-05 18:12:00 (GMT)
commitedc9d85c68af600431556f3e8edae9b0fbfdfd34 (patch)
tree50fce0cb160e75cd13f46888765bda4dab3ba59b /Lib/dataclasses.py
parentd444dec09ae05150f0d339a060fca23990d4834e (diff)
downloadcpython-edc9d85c68af600431556f3e8edae9b0fbfdfd34.zip
cpython-edc9d85c68af600431556f3e8edae9b0fbfdfd34.tar.gz
cpython-edc9d85c68af600431556f3e8edae9b0fbfdfd34.tar.bz2
gh-109653: Just import `recursive_repr` in `dataclasses` (gh-109822)
Diffstat (limited to 'Lib/dataclasses.py')
-rw-r--r--Lib/dataclasses.py26
1 files changed, 3 insertions, 23 deletions
diff --git a/Lib/dataclasses.py b/Lib/dataclasses.py
index 3335821..45ce5a9 100644
--- a/Lib/dataclasses.py
+++ b/Lib/dataclasses.py
@@ -4,10 +4,9 @@ import copy
import types
import inspect
import keyword
-import functools
import itertools
import abc
-import _thread
+from reprlib import recursive_repr
from types import FunctionType, GenericAlias
@@ -245,25 +244,6 @@ _ATOMIC_TYPES = frozenset({
property,
})
-# This function's logic is copied from "recursive_repr" function in
-# reprlib module to avoid dependency.
-def _recursive_repr(user_function):
- # Decorator to make a repr function return "..." for a recursive
- # call.
- repr_running = set()
-
- @functools.wraps(user_function)
- def wrapper(self):
- key = id(self), _thread.get_ident()
- if key in repr_running:
- return '...'
- repr_running.add(key)
- try:
- result = user_function(self)
- finally:
- repr_running.discard(key)
- return result
- return wrapper
class InitVar:
__slots__ = ('type', )
@@ -322,7 +302,7 @@ class Field:
self.kw_only = kw_only
self._field_type = None
- @_recursive_repr
+ @recursive_repr()
def __repr__(self):
return ('Field('
f'name={self.name!r},'
@@ -632,7 +612,7 @@ def _repr_fn(fields, globals):
for f in fields]) +
')"'],
globals=globals)
- return _recursive_repr(fn)
+ return recursive_repr()(fn)
def _frozen_get_del_attr(cls, fields, globals):