使用 pylint 的 python 代码约定
我正在尝试 pylint 来检查我的源代码的约定。 不知何故,某些变量名称与常量的正则表达式 (const-rgx
) 匹配,而不是与变量名称正则表达式 (variable-rgx
) 匹配。 如何将变量名与variable-rgx
匹配? 或者我应该用我的 variable-rgx
东西扩展 const-rgx
吗?
例如C0103:31:名称“settings”无效(应匹配 (([A-Z_][A-Z1-9_]*)|(__.*__))$)
I'm trying out pylint to check my source code for conventions. Somehow some variable names are matched with the regex for constants (const-rgx
) instead of the variable name regex (variable-rgx
). How to match the variable name with variable-rgx
? Or should I extend const-rgx
with my variable-rgx
stuff?
e.g.C0103: 31: Invalid name "settings" (should match (([A-Z_][A-Z1-9_]*)|(__.*__))$)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这些变量是在模块级别声明的吗? 也许这就是为什么它们被视为常量(至少根据 PEP-8,它们应该是这样声明的)。
Are those variables declared on module level? Maybe that's why they are treated as constants (at least that's how they should be declared, according to PEP-8).
我只是禁用该警告,因为我不遵循这些命名约定。
为此,请将此行添加到模块的顶部:
如果要全局禁用它,请将其添加到 pylint 命令中:
I just disable that warning because I don't follow those naming conventions.
To do that, add this line to the top of you module:
If you want to disable that globally, then add it to the pylint command:
就像你说的那样, const-rgx 只匹配大写名称或双下划线包围的名称。
变量-rgx 是
如果你的变量被称为“设置”,它确实应该与变量-rgx 相匹配,
我只能想到两个原因。
设置要么是常量,要么是 PyLint 中的错误。
like you said that is the const-rgx that is only matching UPPERCASE names, or names surrounded by double underscores.
the variables-rgx is
if your variable is called 'settings' that indeed should match the variables-rgx
I can think of only 2 reasons for this..
either settings is a constant or it is a bug in PyLint.