相关疑难解决方法(0)

mypy:与超级类型“序列”不兼容的“ __getitem__”签名

我有一个MutableSequence像这样继承的类:

class QqTag(MutableSequence):
    def __init__(self):
        self._children = []
    def __getitem__(self, idx: int) -> 'QqTag':
        return self._children[idx]
Run Code Online (Sandbox Code Playgroud)

mypy抱怨Signature of "__getitem__" incompatible with supertype "Sequence"

在中Sequence,此方法定义为:

@abstractmethod
def __getitem__(self, index):
    raise IndexError
Run Code Online (Sandbox Code Playgroud)

那么,这是什么问题?为什么mypy对我的实施不满意?

python typechecking mypy

5
推荐指数
1
解决办法
458
查看次数

标签 统计

mypy ×1

python ×1

typechecking ×1