忽略带有Pyright的特定未定义变量
当使用VSCODE和PYRIGHT编写自定义Saltstack模块/状态时,我到处都会遇到以下错误:
"__salt__" is not defined
这不是杀手,因为我可以将以下内容放在引用它的每一行的末尾
# pyright: ignore[reportUndefinedVariable]
:做是告诉我的项目,__盐__
是已知变量,并且不要在该变量上报告。
这可能吗?
When writing custom SaltStack modules/states using VScode and linting with pyright, I get the following error all over the place:
"__salt__" is not defined
It's not a killer, because I can put the following on the end of every line that references it:
# pyright: ignore[reportUndefinedVariable]
But what I would rather do is tell my project that __salt__
is a known variable, and don't report on that variable.
Is this possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
更多
发布评论
评论(2)
您可以通过在
__内置__。pyi
文件中声明变量来做到这一点。参见 this 。You can do so by declaring the variable in the
__builtins__.pyi
file. See this.我最终制定了正确的解决方案,该解决方案可与3.5更新的Python一起使用,并且我绊倒了所有变量。
I eventually worked out the correct solution which works with python newer than 3.5 and all the variables I'm tripping over.