MCPcopy Create free account
hub / github.com/numpy/numpy / _recursive_guard

Function _recursive_guard

numpy/core/arrayprint.py:493–519  ·  view source on GitHub ↗

Like the python 3.2 reprlib.recursive_repr, but forwards *args and **kwargs Decorates a function such that if it calls itself with the same first argument, it returns `fillvalue` instead of recursing. Largely copied from reprlib.recursive_repr

(fillvalue='...')

Source from the content-addressed store, hash-verified

491
492
493def _recursive_guard(fillvalue='...'):
494 """
495 Like the python 3.2 reprlib.recursive_repr, but forwards *args and **kwargs
496
497 Decorates a function such that if it calls itself with the same first
498 argument, it returns `fillvalue` instead of recursing.
499
500 Largely copied from reprlib.recursive_repr
501 """
502
503 def decorating_function(f):
504 repr_running = set()
505
506 @functools.wraps(f)
507 def wrapper(self, *args, **kwargs):
508 key = id(self), get_ident()
509 if key in repr_running:
510 return fillvalue
511 repr_running.add(key)
512 try:
513 return f(self, *args, **kwargs)
514 finally:
515 repr_running.discard(key)
516
517 return wrapper
518
519 return decorating_function
520
521
522# gracefully handle recursive calls, when object arrays contain themselves

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected