[Python-Dev] Adding functools.decorator (original) (raw)
Georg Brandl g.brandl at gmx.net
Sun Apr 30 17:23:53 CEST 2006
- Previous message: [Python-Dev] Adding functools.decorator
- Next message: [Python-Dev] Adding functools.decorator
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Nick Coghlan wrote:
Collin Winters has done the work necessary to rename PEP 309's functional module to functools and posted the details to SF [1].
I'd like to take that patch, tweak it so the C module is built as functools rather than functools, and then add a functools.py consisting of:
I'm all for it. (You could integrate the C version of "decorator" from my SF patch, but I think Python-only is enough).
from functools import * # Pick up functools.partial
def updatewrapper(decorated, func, decofunc): # Support naive introspection decorated.module = func.module decorated.name = func.name decorated.doc = func.doc decorated.dict.update(func.dict) # Provide access to decorator and original function decorated.decorator = decofunc decorated.decorates = func def decorator(decofunc): """Wrap a function as an introspection friendly decorator function""" def wrapper(func): decorated = decofunc(func) if decorated is func: return func updatewrapper(decorated, func, decofunc) return decorated # Manually make this decorator introspection friendly updatewrapper(wrapper, decofunc, decorator) return wrapper After typing those four lines of boilerplate to support naive introspection out in full several times for contextlib related decorators, I can testify that doing it by hand gets old really fast :)
Agreed.
Georg
- Previous message: [Python-Dev] Adding functools.decorator
- Next message: [Python-Dev] Adding functools.decorator
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]