refactoring Comparisons to singletons like None

Issue #113 resolved
Reimar Bauer created an issue

We have a lot places in the codebase where None comparision is casted to bolean but it should always be done with 'is' or 'is not', never the equality operators.

if x: #x is treated True except for all empty data types [],{},(),'',0 False, and None

From PEP8

Comparisons to singletons like None should always be done with is or is not , never the equality operators.

Also, beware of writing if x when you really mean if x is not None -- e.g. when testing whether a variable or argument that defaults to None was set to some other value. The other value might have a type (such as a container) that could be false in a boolean context!

Use is not operator rather than not ... is . While both expressions are functionally identical, the former is more readable and preferred.

Yes:

if foo is not None:

No:

if not foo is None:

Comments (3)

  1. Log in to comment