In some Python code I'm working on I spot here and there so-called 'Yoda conditions'.
Examples are:
if 0 < len(someList): ...
if None != ComputeSomething(): ...
Is there a way to have them flagged by PyLint?
Pylint currently implements this as convention check 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.
From the features documentation:
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.
Example output:
C:130, 3: Comparison should be __name__ == '__main__' (misplaced-comparison-constant)