我正在试用 python 的海龟模块,虽然程序正确执行,但 PyLint 一直错误地将程序的某些部分标记为错误。程序 polygon.py
包括以下内容:
import turtle
t = turtle.Turtle()
t.fd(100)
turtle.mainloop()
这个程序按预期执行,乌龟向前移动了 100 个像素。但是,在 VSCode 中,PyLint 将 turtle.mainloop()
下划线作为错误,说:
Module 'turtle' has no 'mainloop' member pylint(no-member)
此外,在实际的 turtle.py
模块中,对 mainloop()
以及其他一些成员的提及也被标记为错误,表示:
"mainloop" is not defined Pylance (reportUndefinedVariable)
我尝试卸载并重新安装 PyLint,尽管错误继续显示。考虑到程序在其他方面工作正常,我该如何修复它们,或者至少隐藏它们?
答案 0 :(得分:1)
经过一番搜索,我找到了一个解决误报无成员错误的方法。对于 PyLint,到对应的 JSON 文件中添加:
"python.linting.pylintArgs":[
"--generated-members"
]
代表问题作者添加。