Skip to content

None Compare

Sourcery refactoring id: none-compare


Replaces == with is when comparing to None


if hat == None:
    raise NoHatException


if hat is None:
    raise NoHatException


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.