我正在尝试使用静态类型检查工具来检查对变量的错误分配。例如,将字符串分配给 int 变量。
我试过pytype和mypy。两者都没有给我任何警告。
class A:
def __init__(self):
self.x : int = None
if __name__ == '__main__':
a = A()
a.x = 'abc'
print(a.x)
我希望静态类型检查工具可以在上面的行中给我一个警告:
a.x = 'abc'
我是否需要使用一些选项或其他辅助工具来检测这种赋值语句?