跳到内容

empty-method-without-abstract-decorator (B027)

源自 flake8-bugbear linter。

作用

检查抽象基类中没有抽象装饰器的空方法。

为什么这不好?

抽象基类中没有抽象装饰器的空方法可能表明存在错误。 如果该方法应该是抽象的,请向该方法添加 @abstractmethod 装饰器。

示例

from abc import ABC


class Foo(ABC):
    def method(self): ...

建议改为

from abc import ABC, abstractmethod


class Foo(ABC):
    @abstractmethod
    def method(self): ...

参考