如何修复“缺少模块 docstringpylint(missing-module-docstring)”

问题描述 投票:0回答:5

我在 VS Code 上使用 pygame 模块,遇到了 pygame 没有 init 成员的问题。我按照this链接的解决方案进行操作。我编辑了用户设置并添加了

"python.linting.pylintArgs": [
    "--extension-pkg-whitelist=pygame",
    "--unsafe-load-any-extension=y"
]

到json文件末尾

pygame问题已解决。然而,当我使用

import random
时。我收到此警告:

缺少模块 docstringpylint(missing-module-docstring)

如何让它消失?另外,有没有更好的办法解决pygame的init问题?

python visual-studio-code pygame pylint docstring
5个回答
34
投票

Python 模块的文档字符串记录了该文件内容的用途。

您可以通过在模块顶部添加文档字符串来解决此错误:

"""
Provides some arithmetic functions
"""

def add(a, b):
  """Add two numbers"""
  return a + b

def mult(a, b): 
  """Multiply two numbers"""
  return a * b

了解更多信息https://www.python.org/dev/peps/pep-0257/#multi-line-docstrings


21
投票

我刚刚弄清楚文档字符串是什么。它们只是描述函数或类。它用三个双引号或单引号括起来。 帮助了我。

要删除 VSCode 中的文档字符串警告,我只需将

"--disable=C0111"
添加到
"python.linting.pylintArgs": []
,它位于用户的 JSON 设置中。


5
投票

我在 VsCode 中添加了以下设置以禁用所有文档字符串警告。

"python.linting.pylintArgs": [
  "--disable=missing-module-docstring",
  "--disable=missing-class-docstring",
  "--disable=missing-function-docstring"
]

0
投票

当我们在没有 .pylintrc 的目录中使用 pylint 时,就会出现此错误。转到具有 .pylintrc 的目录并从那里运行。

示例:

测试/ 测试1.py 测试2/测试2.py .pylintrc

如果你想在 test/test2 中运行 test2.py 的 pylint 那么你会得到这个错误。

test/test2$ pylint test2.py  is wrong.

test$ pylint test2.py is correct.

0
投票

此答案已随扩展程序的文档更新 在 vscode 的 settings.json 中添加以下代码

"pylint.args": [
    "--disable=missing-module-docstring",
    "--disable=missing-class-docstring",
    "--disable=missing-function-docstring"
],

这将禁用模块、类和函数文档字符串的警告

参考:扩展程序的文档

© www.soinside.com 2019 - 2024. All rights reserved.