Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/358.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 自动文档字符串和注释拼写检查_Python_Code Analysis_Pylint_Static Code Analysis - Fatal编程技术网

Python 自动文档字符串和注释拼写检查

Python 自动文档字符串和注释拼写检查,python,code-analysis,pylint,static-code-analysis,Python,Code Analysis,Pylint,Static Code Analysis,考虑以下示例代码: # -*- coding: utf-8 -*- """Test module.""" def test(): """Tets function""" return 10 pylint给出了10个警告,flake8没有找到任何警告: $ pylint test.py ... Global evaluation ----------------- Your code has been rated at 10.00/10 ... $ flake8 test.

考虑以下示例代码:

# -*- coding: utf-8 -*-
"""Test module."""


def test():
    """Tets function"""
    return 10
pylint
给出了10个警告,
flake8
没有找到任何警告:

$ pylint test.py 
...
Global evaluation
-----------------
Your code has been rated at 10.00/10
...
$ flake8 test.py
$
但是,正如您所看到的,
test
函数的docstring中有一个输入错误。而且,您的编辑器可能会自动突出显示它,例如,Pycharm是如何做到这一点的:

多亏了这个主题,现在我知道有一个相关的拼写检查库,名为,可以用来检测拼写错误

我的最终目标是自动检测项目中的拼写错误,并使拼写检查成为连续构建、测试和代码质量检查运行的一部分

有没有办法通过
pylint
实现这一点?如果没有,我也希望您能给我一些提示,说明如何将
PyEnchant
应用到docstring和注释项目中(在这种情况下,可以使用
pylint
pyflakes
插件)


另外,如果我对代码质量非常担心,请告诉我。

Pylint刚刚发布了1.4.0,其中包括一个。这是首字母

请注意,要使检查器工作,您需要安装python模块并在系统范围内安装一个库。在mac上,它可以通过brew安装:

$ brew install enchant
默认情况下,将关闭
拼写检查程序。您可以在pylint
rc
配置文件中或从命令行启用它:

$ cat test.py
# I am the tyop

$ pylint --disable all --enable spelling --spelling-dict en_US test.py
C:  1, 0: Wrong spelling of a word 'tyop' in a comment:
# I am the tyop
           ^^^^
Did you mean: 'typo' or 'top' or 'tip' or 'topi'? (wrong-spelling-in-comment)

OP的可能副本实际上已经在他的问题中提到了这一点。@user3426575这正是我提到这个主题的原因。“另外,如果我对代码质量非常担心,请告诉我。”-一点也不!)如果我有一个讨厌的地方,那就是有拼写和/或语法错误的文档。程序员执行代码;他们阅读文档。因此,让您继续“什么?!”的文档违背了它最初存在的唯一目的。@iCodez phew,很高兴我们相信并遵循同样的原则。谢谢。谢谢您添加说明!我在真实的代码上尝试了它,这有点困难:它不知道如何忽略代码示例、URL和其他ReST标记,因此变量名被标记为拼写错误等。是的,可能有一个非常长的要忽略的单词列表(
拼写忽略单词
设置),最终可能很难维护。无论如何,我会在一个真正的项目上试一试。谢谢。对于非mac用户,
pip安装-U pyenchant
应该完成这项工作。对我来说,这会检查所有内容(变量、类等)。我希望它是做一个py文件中的docstring和注释只。我想我做错了什么,但我不确定是什么