Skip to content

Equality Identity

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: equality-identity

Section titled “Sourcery refactoring id: equality-identity”

Simplify equality comparisons that are always True or False

if 1 == 1:
always_do_this()
if 1 != 1:
never_do_this()
if True:
always_do_this()
if False:
never_do_this()

When comparing a value to itself, the outcome will always be True, as long as the equality operator has not been overridden, and this also holds for the opposite comparison and False. It is more readable to use a direct comparison to the boolean value.