johhny B
johhny B

Reputation: 1452

Order of decorator for abstract method

I have a base class which I have made abstract.

class X(metaclass=ABCMeta):

   @abstractmethod
   @tornado.gen.coroutine
   def cc(self):
      # do stuff

What should the order of the decorators go in? And does it matter?

Upvotes: 1

Views: 1156

Answers (1)

miradulo
miradulo

Reputation: 29720

The order of stacked function decorators usually does matter for correct interpretation (based on the flow of your program), and in this case it is stated explicitly in the docs:

When abstractmethod() is applied in combination with other method descriptors, it should be applied as the innermost decorator...

So in your case, you should swap the order to make it the innermost decorator.

class X(metaclass=ABCMeta):

    @tornado.gen.coroutine
    @abstractmethod
    def cc(self):
       # do stuff

Upvotes: 4

Related Questions