MCPcopy Index your code
hub / github.com/python/cpython / recursive_repr

Function recursive_repr

Lib/reprlib.py:9–36  ·  view source on GitHub ↗

Decorator to make a repr function return fillvalue for a recursive call

(fillvalue='...')

Source from the content-addressed store, hash-verified

7from _thread import get_ident
8
9def recursive_repr(fillvalue='...'):
10 'Decorator to make a repr function return fillvalue for a recursive call'
11
12 def decorating_function(user_function):
13 repr_running = set()
14
15 def wrapper(self):
16 key = id(self), get_ident()
17 if key in repr_running:
18 return fillvalue
19 repr_running.add(key)
20 try:
21 result = user_function(self)
22 finally:
23 repr_running.discard(key)
24 return result
25
26 # Can't use functools.wraps() here because of bootstrap issues
27 wrapper.__module__ = getattr(user_function, '__module__')
28 wrapper.__doc__ = getattr(user_function, '__doc__')
29 wrapper.__name__ = getattr(user_function, '__name__')
30 wrapper.__qualname__ = getattr(user_function, '__qualname__')
31 wrapper.__annotate__ = getattr(user_function, '__annotate__', None)
32 wrapper.__type_params__ = getattr(user_function, '__type_params__', ())
33 wrapper.__wrapped__ = user_function
34 return wrapper
35
36 return decorating_function
37
38class Repr:
39 _lookup = {

Callers 3

partialClass · 0.90
MyContainer3Class · 0.90
XClass · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…