Skip to content

comparison-with-itself (PLR0124)

Added in v0.0.273 · Category: suspicious · Related issues · View source

Derived from the Pylint linter.

What it does

Checks for operations that compare a name to itself.

Why is this bad?

Comparing a name to itself typically results in a truthy value, and is likely a mistake.

Example

foo == foo

In some cases, self-comparisons are used to determine whether a float is NaN. Instead, prefer math.isnan:

import math

math.isnan(foo)

References