Skip to content

Commit edc9d85

Browse files
authored
gh-109653: Just import recursive_repr in dataclasses (gh-109822)
1 parent d444dec commit edc9d85

File tree

1 file changed

+3
-23
lines changed

1 file changed

+3
-23
lines changed

Lib/dataclasses.py

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@
44
import types
55
import inspect
66
import keyword
7-
import functools
87
import itertools
98
import abc
10-
import _thread
9+
from reprlib import recursive_repr
1110
from types import FunctionType, GenericAlias
1211

1312

@@ -245,25 +244,6 @@ def __repr__(self):
245244
property,
246245
})
247246

248-
# This function's logic is copied from "recursive_repr" function in
249-
# reprlib module to avoid dependency.
250-
def _recursive_repr(user_function):
251-
# Decorator to make a repr function return "..." for a recursive
252-
# call.
253-
repr_running = set()
254-
255-
@functools.wraps(user_function)
256-
def wrapper(self):
257-
key = id(self), _thread.get_ident()
258-
if key in repr_running:
259-
return '...'
260-
repr_running.add(key)
261-
try:
262-
result = user_function(self)
263-
finally:
264-
repr_running.discard(key)
265-
return result
266-
return wrapper
267247

268248
class InitVar:
269249
__slots__ = ('type', )
@@ -322,7 +302,7 @@ def __init__(self, default, default_factory, init, repr, hash, compare,
322302
self.kw_only = kw_only
323303
self._field_type = None
324304

325-
@_recursive_repr
305+
@recursive_repr()
326306
def __repr__(self):
327307
return ('Field('
328308
f'name={self.name!r},'
@@ -632,7 +612,7 @@ def _repr_fn(fields, globals):
632612
for f in fields]) +
633613
')"'],
634614
globals=globals)
635-
return _recursive_repr(fn)
615+
return recursive_repr()(fn)
636616

637617

638618
def _frozen_get_del_attr(cls, fields, globals):

0 commit comments

Comments
 (0)