Proposal
Disallow ternary operations that:
- if
condition holds, call a method
- otherwise, do nothing (the whole expression evaluates to
None)
e.g. method(...) if condition else None
Why is it bad?
Can be autofixed, simplified, and be clearer for future maintainers.
Examples & autofix
- print("🐍") if condition else None
+ if condition:
+ print("🐍")
- dictionary.update({"foo":"bar"}) if condition else None
+ if condition:
+ dictionary.update({"foo":"bar"})
(the second example can be simplified to dictionary["foo"]="bar", but the example is what inspired this proposal, and the simplification doesn't serve as good example)