[Python-Dev] Proposed tweaks to functools.wraps
Raymond Hettinger
raymond.hettinger at gmail.com
Wed Aug 11 21:16:54 CEST 2010
On Aug 11, 2010, at 6:00 AM, Steven D'Aprano wrote:
> @wraps(f)
> def func(*args):
> do_something()
> return f(*args)
>
> then func.__wrapped__ gives f. If f itself wraps (say) g, and g wraps h,
> then you have:
>
> func.__wrapped__ => f
> func.__wrapped__.__wrapped__ => g
> func.__wrapped__.__wrapped__.__wrapped__ => h
>
> and so on, until you reach a function that doesn't wrap anything and
> doesn't have a __wrapped__ attribute.
>
>
> I'm +1 on the proposal.
+1 from me also.
The ability to introspect is basic to Python's design.
Objects know their class, functions know their code objects,
bound methods know both their underlying function,
classes know their own class dictionary, etc.
Raymond
More information about the Python-Dev
mailing list