None Compare
Documentation Index
Fetch the complete documentation index at: https://docs.sourcery.ai/llms.txt
Use this file to discover all available pages before exploring further.
Sourcery refactoring id: none-compare
Section titled “Sourcery refactoring id: none-compare”Description:
Section titled “Description:”Replaces == with is when comparing to None
Before:
Section titled “Before:”if hat == None: raise NoHatExceptionAfter:
Section titled “After:”if hat is None: raise NoHatExceptionExplanation:
Section titled “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.