[issue13266] Add inspect.unwrap(f) to easily unravel "__wrapped__" chains

Nick Coghlan report at bugs.python.org
Mon Jul 15 14:55:32 CEST 2013


Nick Coghlan added the comment:

Added a version that allows the iteration to be terminated early if certain criteria are met, which is needed for a robust implementation of inspect.signature.

However, I'm thinking the callback based approach in this version isn't especially Pythonic, so I'm thinking it may be better to change the API to a generator function. That way the iterator can still take care of the wrapper loop detection, without needing the clumsy predicate API for early termination.

Instead, you would just use an ordinary search loop, and if you wanted the innermost function unconditionally you could do something like:

    for f in functools.unwrap(original): pass
    # f is now the innermost function

----------
Added file: http://bugs.python.org/file30927/issue13266_inspect_unwrap_4.diff

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue13266>
_______________________________________


More information about the Python-bugs-list mailing list