带有 mypy 类型检查的方法解析顺序 (MRO)?

问题描述

在使用自定义 django mixin 时,我遇到了具有以下结构的代码

class A:
    def method(self,i): # this is a method provided by django,so can't easily change this signature
        print(f"A: {i}")


class B:
    def method(self,i: int): # with type hint
        print(f"B: {i}")
        super().method(i)


class C(B,A):
    pass

# at some point
C().method(0)

mypy 给出 error: "method" undefined in superclass。目前,我使用的解决方法是将 method 视为动态类型(即删除 int)。是否可以(或是否有意义)添加类型注释,以便将 method 视为静态类型?谢谢!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)