我刚刚开始使用 mypy 来检查我的代码,发现一个我无法理解的错误,类似于 this one。
我理解问题及其答案,并且它有效。 尽管如此,当我拆分文件并导入它们时,我仍然收到错误。 使用与问题答案相同的类:
文件
parent.py
class Parent:
def __init_subclass__(cls, handler=None):
super().__init_subclass__()
cls.handler = handler
文件
child.py
from parent import Parent
class CorrectChild(Parent, handler=5):
{Unexpected keyword argument "handler" for "__init_subclass__" of "object"mypy(error)}
pass
当我将正确的子文件放入父文件中时,问题就消失了,但我不想这样做,因为我的实际文件太长了。
不知道是否有用,但我在 vscode 中遇到错误。
这是 MyPy 中的一个错误,很可能与您的代码无关:https://github.com/python/mypy/issues/11036