如何在 vscode 和 mypy 之间同步类型提示
例如,以下(愚蠢)示例将在vscode中引起错误:
class Something:
def __init__(self, x):
self.x = x
def something_else(self, y) -> Something:
return Something(self.x + y)
在此处看到:
其中aS mypy script.py
将不会返回任何错误。
我不确定这里有什么区别,但是我宁愿将其优先考虑,因为这是我用来捕获类型错误的原因。
For example the following (silly) example will raise an error within vscode:
class Something:
def __init__(self, x):
self.x = x
def something_else(self, y) -> Something:
return Something(self.x + y)
Seen here:
Where as mypy script.py
will return no errors.
I'm not sure what the difference is here, but I'd rather mypy took priority as that's what I'm using to catch type errors.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
某物
未定义,因为在类定义完成之前,它将无法定义。您会注意到,运行此代码会导致nameError
,因此在这种情况下,Pylance和Pylint是正确的,您可能不应该使他们的警告保持沉默。请参阅这个问题如何解决该问题。
Something
isn't defined as it won't be defined until the class definition is complete. You'll notice that running this code will cause aNameError
, so in this case Pylance and Pylint are correct and you probably shouldn't silence their warnings.Refer to this question for how to fix that.