Making a decorator a staticmethod

  • Thread starter Bruno Desthuilliers
  • Start date
B

Bruno Desthuilliers

Zac Burns a écrit :
I have a decorator in a class

Why ?

(snip)
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)"

Just make it a plain function and you'll be fine.
 
Z

Zac Burns

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,775
Messages
2,569,601
Members
45,182
Latest member
alexanderrm

Latest Threads

Top