Making a decorator a staticmethod

Zac Burns zac256 at
Thu Jan 8 19:54:31 CET 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

	def testDecorated(self):
		return None
class D(C):
	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
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
Aim - Zac256FL
Production Engineer (Digital Overlord)
Zindagi Games

More information about the Python-list mailing list