use*_*619 7 python pylint pylintrc
我正在使用我的pylintrc文件创建一个简单项目,并为测试方法获取此错误:
method name - test_calculator_add_method_returns_correct_result - doesn't conform to snake_case naming style
Run Code Online (Sandbox Code Playgroud)
class TddInPythonExample(unittest.TestCase):
""" This is a basic test class"""
def test_calculator_add_method_returns_correct_result(self):
""" This test the calculator add method """
calc = Calculator()
result = calc.add(2,2)
self.assertEqual(4, result)
Run Code Online (Sandbox Code Playgroud)
jrt*_*ell 18
根据这个显示:http://pylint-messages.wikidot.com/messages:c0103,名称的长度上限为30个字符,其中您的方法名称长度为49个字符
您可以缩短方法名称,或更改配置以允许更长的方法
Bar*_*eby 12
如果您是想要忽略此问题的 Visual Studio Code 用户,您可以添加python.linting.pylintArgs到.vscode/settings.json:
{
...
"python.linting.pylintArgs": [
"--disable=C0103"
]
...
}
Run Code Online (Sandbox Code Playgroud)
Aka*_*ain 10
@jrtapsell 指出得很好
在命名约定方面,为每种类型定义了一个正则表达式。
您可能会注意到,名称的长度及其正则表达式可以从 2 到 30 个字符不等。
+-------------------+---------------+-------------------------------------------+
| Type | Option | Default regular expression |
+-------------------+---------------+-------------------------------------------+
| Argument | argument-rgx | [a-z_][a-z0-9_]{2,30}$ |
| Attribute | attr-rgx | [a-z_][a-z0-9_]{2,30}$ |
| Class | class-rgx | [A-Z_][a-zA-Z0-9]+$ |
| Constant | const-rgx | (([A-Z_][A-Z0-9_]*)|(__.*__))$ |
| Function | function-rgx | [a-z_][a-z0-9_]{2,30}$ |
| Method | method-rgx | [a-z_][a-z0-9_]{2,30}$ |
| Module | module-rgx | (([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$ |
| Variable | variable-rgx | [a-z_][a-z0-9_]{2,30}$ |
| Variable, inline1 | inlinevar-rgx | [A-Za-z_][A-Za-z0-9_]*$ |
+-------------------+---------------+-------------------------------------------+
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
10114 次 |
| 最近记录: |