[Python-Dev] update_wrapper should preserve staticmethod behavior (original) (raw)

Guido van Rossum guido at python.org
Wed Jun 11 19:39:26 CEST 2008


Please submit a fix to the issue tracker at bugs.python.org if you care about this.

On Wed, Jun 11, 2008 at 7:06 AM, Calvin Spealman <ironfroggy at socialserve.com> wrote:

I'd like to make a claim about the following example, that updatewrapper should be improved to preserve the behavior of known, built-in decorators. In this case, I'm talking about staticmethod. The order I list here feels natural, but it obviously doesn't work. The only reason it doesn't seems to be that it is trying to decorate the descriptor, not the function itself. This is expected, but it could certainly be smart enough to detect a descriptor and attempt to get the actual callable underneath, could it not? It would not work for all cases, of course.

def d(f): ... def nf(*a, **kw): ... print "decorated function called" ... return f(*a, **kwargs) ... functools.updatewrapper(nf, f) ... return nf ... class A(object): ... @d ... @staticmethod ... def a(self): ... print "a" ... Traceback (most recent call last): File "", line 1, in File "", line 3, in A File "", line 5, in d File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/functools.py", line 33, in updatewrapper setattr(wrapper, attr, getattr(wrapped, attr)) AttributeError: 'staticmethod' object has no attribute 'module'


Python-Dev mailing list Python-Dev at python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/guido%40python.org

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



More information about the Python-Dev mailing list