忽略MyPy“作为类型无效”错误

2024-04-16 06:57:34 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在维护一个Python 3.3库。我已经更新了MyPy,现在我得到了“is not valid as a type”错误

有问题的代码在enum包中,我已经出售了这个包。在mypi.ini中,我忽略了该包中的所有错误,但从技术上讲,错误发生在我在自己的代码中将Enum用作超类的地方

有没有办法让MyPy确信Enum确实是一种类型?我不希望在代码中添加忽略

例如:

from .vendor.python.enum import Enum

class ExampleEnum(Enum):
    Hello = 1

MyPy产生以下错误:

st3/sublime_lib/footest.py:3: error: Variable "sublime_lib.vendor.python.enum.Enum" is not valid as a type
st3/sublime_lib/footest.py:3: note: See https://mypy.readthedocs.io/en/latest/common_issues.html#variables-vs-type-aliases

Tags: 代码islibastype错误notenum