None Compare¶
Sourcery refactoring id: none-compare¶
Description:¶
Replaces == with is when comparing to None
Before:¶
if hat == None:
raise NoHatException
After:¶
if hat is None:
raise NoHatException
Explanation:¶
In Python is refers to reference equality - where you want to check if
something is the same object. Equals == checks value equality, to check that
the objects are equal to each other. In Python the None object is a singleton,
so it is correct to use is when comparing to it.