Making a decorator a staticmethod

Zac Burns zac256 at gmail.com
Thu Jan 8 13:54:31 EST 2009


I have a decorator in a class to be used by that class and by inheriting classes

######
class C(object):
	@staticmethod # With  this line enabled or disabled usage in either C
or D will be broken. To see that D works remember to remove usage in C
	def decorateTest(func):
		def newFunc(*args, **kwargs):
			print args, kwargs
			return func(*args, **kwargs)
		return newFunc

	@decorateTest
	def testDecorated(self):
		return None
class D(C):
	@C.decorateTest
	def test2(self):
		return None
######

The exception that I get when using it as a staticmethod and try to
use it in the baseclass is "TypeError: 'staticmethod' object is not
callable".
When it is not staticmethod the exception I get in the extension class
is is "TypeError: unbound method decorateTest() must be called with C
instance as first argument (got function instance instead)"

Python version is 2.5.1

--
Zachary Burns
(407)590-4814
Aim - Zac256FL
Production Engineer (Digital Overlord)
Zindagi Games



More information about the Python-list mailing list