[issue13266] Add inspect.unwrap(f) to easily unravel __wrapped__ chains
Roundup Robot added the comment: New changeset 2aa6c1e35b8a by Nick Coghlan in branch 'default': Close #13266: Add inspect.unwrap http://hg.python.org/cpython/rev/2aa6c1e35b8a -- nosy: +python-dev resolution: - fixed stage: patch review - committed/rejected status: open - closed ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue13266 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue13266] Add inspect.unwrap(f) to easily unravel __wrapped__ chains
Aaron Iles added the comment: My +1 is for the callback based approach. The brevity of the search loop for finding the innermost function is (in my opinion at least) non-obvious, relying on for loops not having their own scope as it does. If a generator based API was adopted instead, I propose a convenience function (unwrap_all?) to help developers avoid writing code like: inner = None for inner in functools.unwrap(outer): pass if inner is None: inner = outer Which combines a misunderstanding of the API with for loop scope shortcut. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue13266 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue13266] Add inspect.unwrap(f) to easily unravel __wrapped__ chains
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 rep...@bugs.python.org http://bugs.python.org/issue13266 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue13266] Add inspect.unwrap(f) to easily unravel __wrapped__ chains
Changes by Nick Coghlan ncogh...@gmail.com: -- assignee: - ncoghlan ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue13266 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue13266] Add inspect.unwrap(f) to easily unravel __wrapped__ chains
Changes by Jesús Cea Avión j...@jcea.es: -- nosy: +jcea ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue13266 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue13266] Add inspect.unwrap(f) to easily unravel __wrapped__ chains
Nick Coghlan added the comment: Turns out there's a bug in the implementation of functools.update_wrapper :P Added that as a dependency, since this API doesn't make sense until update_wrapper is behaving itself. The new tests didn't pick it up because they don't use wraps or update_wrapper, they set __wrapped__ directly. Also, the replacement of the recursion in inspect.signature is incorrect - we want to interleave checks for __signature__ as we recurse through the stack of wrapper functions. -- dependencies: +functools.update_wrapper mishandles __wrapped__ ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue13266 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue13266] Add inspect.unwrap(f) to easily unravel __wrapped__ chains
Changes by Daniel Urban urban.dani...@gmail.com: -- stage: needs patch - patch review ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue13266 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue13266] Add inspect.unwrap(f) to easily unravel __wrapped__ chains
Daniel Urban added the comment: I've attached a patch addressing the comments on Rietveld. I've added another modification: inspect.signature uses inspect.unwrap. (It already tried to unwrap the function, but it wasn't protected from infinite recursion. I don't know if this worth fixing in 3.3.) -- Added file: http://bugs.python.org/file27876/inspect_unwrap_3.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue13266 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue13266] Add inspect.unwrap(f) to easily unravel __wrapped__ chains
Aaron Iles added the comment: I've updated the patch for the current default branch (to be Python 3.4) and added documentation to the inspect module for the new unwraps function. Functionally unwraps and it's tests are unchanged. -- Added file: http://bugs.python.org/file27790/p13266-2.diff ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue13266 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue13266] Add inspect.unwrap(f) to easily unravel __wrapped__ chains
Changes by Aaron Iles aaron.i...@gmail.com: -- nosy: +aliles ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue13266 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue13266] Add inspect.unwrap(f) to easily unravel __wrapped__ chains
Changes by Éric Araujo mer...@netwok.org: -- versions: +Python 3.4 -Python 3.3 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue13266 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue13266] Add inspect.unwrap(f) to easily unravel __wrapped__ chains
Daniel Urban urban.dani...@gmail.com added the comment: I've attached a patch implementing inspect.unwrap (+ some tests). -- keywords: +patch Added file: http://bugs.python.org/file25368/inspect_unwrap.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue13266 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue13266] Add inspect.unwrap(f) to easily unravel __wrapped__ chains
Changes by Meador Inge mead...@gmail.com: -- nosy: +meador.inge ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue13266 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue13266] Add inspect.unwrap(f) to easily unravel __wrapped__ chains
Changes by Éric Araujo mer...@netwok.org: -- nosy: +eric.araujo, rhettinger ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue13266 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue13266] Add inspect.unwrap(f) to easily unravel __wrapped__ chains
Nick Coghlan ncogh...@gmail.com added the comment: After a little thought, I think the explicit unwrap function is the only viable approach. Doing the unwrapping implicitly just has too many nasty corner cases to track down to ensure we aren't losing existing functionality. I'd also suggest that we add a __wrapped__ alias for the 'func' attribute of functools.partial objects. -- title: Support for unwrapping __wrapped__ functions in 'inspect' module - Add inspect.unwrap(f) to easily unravel __wrapped__ chains ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue13266 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue13266] Add inspect.unwrap(f) to easily unravel __wrapped__ chains
Changes by Florent Xicluna florent.xicl...@gmail.com: -- nosy: +flox ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue13266 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue13266] Add inspect.unwrap(f) to easily unravel __wrapped__ chains
Changes by Daniel Urban urban.dani...@gmail.com: -- nosy: +durban ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue13266 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com