@@ -223,6 +223,26 @@ def __repr__(self):
223
223
# https://bugs.python.org/issue33453 for details.
224
224
_MODULE_IDENTIFIER_RE = re .compile (r'^(?:\s*(\w+)\s*\.)?\s*(\w+)' )
225
225
226
+ # This function's logic is copied from "recursive_repr" function in
227
+ # reprlib module to avoid dependency.
228
+ def _recursive_repr (user_function ):
229
+ # Decorator to make a repr function return "..." for a recursive
230
+ # call.
231
+ repr_running = set ()
232
+
233
+ @functools .wraps (user_function )
234
+ def wrapper (self ):
235
+ key = id (self ), _thread .get_ident ()
236
+ if key in repr_running :
237
+ return '...'
238
+ repr_running .add (key )
239
+ try :
240
+ result = user_function (self )
241
+ finally :
242
+ repr_running .discard (key )
243
+ return result
244
+ return wrapper
245
+
226
246
class InitVar :
227
247
__slots__ = ('type' , )
228
248
@@ -280,6 +300,7 @@ def __init__(self, default, default_factory, init, repr, hash, compare,
280
300
self .kw_only = kw_only
281
301
self ._field_type = None
282
302
303
+ @_recursive_repr
283
304
def __repr__ (self ):
284
305
return ('Field('
285
306
f'name={ self .name !r} ,'
@@ -403,27 +424,6 @@ def _tuple_str(obj_name, fields):
403
424
return f'({ "," .join ([f"{ obj_name } .{ f .name } " for f in fields ])} ,)'
404
425
405
426
406
- # This function's logic is copied from "recursive_repr" function in
407
- # reprlib module to avoid dependency.
408
- def _recursive_repr (user_function ):
409
- # Decorator to make a repr function return "..." for a recursive
410
- # call.
411
- repr_running = set ()
412
-
413
- @functools .wraps (user_function )
414
- def wrapper (self ):
415
- key = id (self ), _thread .get_ident ()
416
- if key in repr_running :
417
- return '...'
418
- repr_running .add (key )
419
- try :
420
- result = user_function (self )
421
- finally :
422
- repr_running .discard (key )
423
- return result
424
- return wrapper
425
-
426
-
427
427
def _create_fn (name , args , body , * , globals = None , locals = None ,
428
428
return_type = MISSING ):
429
429
# Note that we may mutate locals. Callers beware!
0 commit comments