This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author ncoghlan
Recipients The Compiler, cjw296, michael.foord, ncoghlan, pstch, yselivanov
Date 2016-08-21.04:35:07
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1471754108.52.0.188697708324.issue25532@psf.upfronthosting.co.za>
In-reply-to
Content
An alternative approach would be to change inspect.unwrap() to use getattr_static() rather than the usual getattr().

The downside of that would be potentially breaking true object proxies, like the 3rd party wrapt module and weakref.proxy.

However, what if inspect.signature implemented a limit on the number of recursive descents it permitted (e.g. based on sys.getrecursionlimit()), and then halted the descent, the same way it does if it finds a `__signature__` attribute on a wrapped object?

`inspect.unwraps` makes that relatively straightforward:

    unwrap_count = 0
    recursion_limit = sys.getrecursionlimit()
    def stop_unwrapping(wrapped):
        nonlocal unwrap_count
        unwrap_count += 1
        return unwrap_count >= recursion_limit
    innermost_function = inspect.unwrap(outer_function, stop=stop_unwrapping)

Alternatively, that hard limit on the recursive descent could be baked directly into the loop detection logic in inspect.unwrap (raising ValueError rather than returning the innermost function reached), as Chris suggested above. We'd then just need to check inspect.signature was handling that potential failure mode correctly.
History
Date User Action Args
2016-08-21 04:35:08ncoghlansetrecipients: + ncoghlan, cjw296, michael.foord, yselivanov, The Compiler, pstch
2016-08-21 04:35:08ncoghlansetmessageid: <1471754108.52.0.188697708324.issue25532@psf.upfronthosting.co.za>
2016-08-21 04:35:08ncoghlanlinkissue25532 messages
2016-08-21 04:35:07ncoghlancreate