[Python-Dev] PEP 318 - writing to func_name attribute (original) (raw)

Guido van Rossum guido at python.org
Fri Aug 6 16:53:51 CEST 2004


One thing I added awhile back to PEP 318 as an open issue is that for ease of writing wrappers the funcname attribute of a function object should be writable. For example, in situations where the decorator returns a new function object (often, I would think) it would really be nice if that new function object had the same name as the undecorated function. Consider:

def a(func): def inner(*args, **kwds): return func(*args, **kwds) return inner @a def func(*args, **kwds): print args print kwds print "func's name:", func.funcname I realize you can use new.function() to create a new function object, but that seems like a fair amount of extra complexity just to change the function's name. I'd prefer it if the decorator could be written as: def a(func): def inner(*args, **kwds): return func(*args, **kwds) inner.funcname = func.funcname return inner That fails because funcname is readonly. Any chance this restriction can be loosened up?

Good idea, independent from decorators; please add it to the PEP!

--Guido van Rossum (home page: http://www.python.org/~guido/)



More information about the Python-Dev mailing list