quantifiedcode / python-anti-patterns

An open collection of Python anti-patterns and worst practices.
https://quantifiedcode.github.io/python-anti-patterns
Other
1.71k stars 249 forks source link

Test for membership should be "not in" #93

Closed GuyHoozdis closed 8 years ago

GuyHoozdis commented 8 years ago

A linter would yeild an error on the anti-pattern code. Even though it is anti-pattern code, it should demonstrate best practices for everything except the anti-pattern being demonstrated.

Although not 'k' in d and 'k' not in d ultimately produce the same bytecode, the former is actually two operations and must be optimized to produce identical bytecode to the latter.

The preferred syntax would be 'k' not in d - per the pep8/flake8 linter.

References:

adewes commented 8 years ago

great, thanks @GuyHoozdis !

GuyHoozdis commented 8 years ago

The Little Book of Python Anti-Patterns is a wonderful resource. It was my pleasure to read and to make this minor contribution. Hopefully, I will be able to contribute more in the future.

Until then...