有没有办法让 PyLint 标志 'Yoda conditions'?
Is there a way to have PyLint flag 'Yoda conditions'?
在我正在处理的一些 Python 代码中,我发现这里那里有所谓的“Yoda conditions”。
例如:
if 0 < len(someList): ...
if None != ComputeSomething(): ...
有没有办法让 PyLint 标记它们?
Pylint 目前将此实现为约定检查 C0122,starting with v1.5.0 (2015-11-29):
Add a new convention message, ‘misplaced-comparison-constant’, emitted when a constant is placed in the left hand side of a comparison, as in ‘5 == func()’. This is also called Yoda condition, since the flow of code reminds of the Star Wars green character, conditions usually encountered in languages with variabile assignments in conditional statements.
misplaced-comparison-constant (C0122):
Comparison should be %s Used when the constant is placed on the left side of a comparison. It is usually clearer in intent to place it in the right hand side of the comparison.
示例输出:
C:130, 3: Comparison should be __name__ == '__main__' (misplaced-comparison-constant)
在我正在处理的一些 Python 代码中,我发现这里那里有所谓的“Yoda conditions”。
例如:
if 0 < len(someList): ...
if None != ComputeSomething(): ...
有没有办法让 PyLint 标记它们?
Pylint 目前将此实现为约定检查 C0122,starting with v1.5.0 (2015-11-29):
Add a new convention message, ‘misplaced-comparison-constant’, emitted when a constant is placed in the left hand side of a comparison, as in ‘5 == func()’. This is also called Yoda condition, since the flow of code reminds of the Star Wars green character, conditions usually encountered in languages with variabile assignments in conditional statements.
misplaced-comparison-constant (C0122):
Comparison should be %s Used when the constant is placed on the left side of a comparison. It is usually clearer in intent to place it in the right hand side of the comparison.
示例输出:
C:130, 3: Comparison should be __name__ == '__main__' (misplaced-comparison-constant)