[issue3445] Ignore missing attributes in functools.update_wrapper

July Tikhonov report at bugs.python.org
Mon May 3 14:43:41 CEST 2010


July Tikhonov <july.tikh at gmail.com> added the comment:

To Evan Klitzke (eklitzke):

>I'm also interested in seeing this fixed. In the current behavior,
>the following code doesn't work:
>
><<< start code
>from functools import wraps
>
>def magic(func):
>	@wraps(func)
>	def even_more_magic(*args):
>		return func(*args)
>	return even_more_magic
>
>class Frob(object):
>	@magic
>	@classmethod
>	def hello(cls):
>		print '%r says hello' % (cls,)
>>>> end code

This code _should not_ work.

[Unbound] classmethod object is not a method or a function, it is even not a callable; it is a descriptor (returning callable). So, it cannot be wrapped or decorated in such way.

If you want something like this to work, you probably should place @classmethod on the upper level (in other words, apply classmethod after all other decorators):

	@classmethod
	@magic
	def hello(cls):
		print '%r says hello' % (cls,)

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue3445>
_______________________________________


More information about the Python-bugs-list mailing list