gpt4 book ai didi

python - 抽象方法的装饰器顺序

转载 作者:行者123 更新时间:2023-12-01 03:52:18 26 4
gpt4 key购买 nike

我有一个已抽象的基类。

class X(metaclass=ABCMeta):

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

装饰器的顺序应该是什么?这重要吗?

最佳答案

堆叠函数装饰器的顺序通常对于正确解释(基于程序的流程)很重要,在这种情况下,它在 the docs 中明确说明。 :

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

因此,在您的情况下,您应该交换顺序以使其成为最里面的装饰器。

class X(metaclass=ABCMeta):

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

关于python - 抽象方法的装饰器顺序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38031932/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com