[issue3445] Ignore missing attributes in functools.update_wrapper

Evan Klitzke report at bugs.python.org
Thu Jan 14 01:50:41 CET 2010


Evan Klitzke <evan at eklitzke.org> added the comment:

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

It fails because classmethods don't have a __module__ attribute, as commented upon elsewhere in this issue. To fix this, you'd either have to either pass in an `assigned` parameter to the `wraps` function, or swap the order of decorator application (i.e. `classmethod(magic(hello))`).

This seems arbitrary and unnecessarily complex; skipping over a missing __module__ should be just fine. Mixing `functools.wraps` and `classmethod` is a relatively common use case that should be as simple as possible.

I've attached a trivial patch which just ignores missing "assigned" attributes.

----------
keywords: +patch
nosy: +eklitzke
Added file: http://bugs.python.org/file15865/fix.patch

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


More information about the Python-bugs-list mailing list