Skip to content

any-eq-parameter

Pythonstyleno fixdefault: offpython/ruff

Reports an __eq__ or __ne__ method whose second parameter is annotated Any.

Python calls __eq__ with any object on the right, so the accurate type is object. With Any a type checker accepts other.value without a check and the method fails at run time on a value of another type.

To fix, annotate other: object and check its type before using it.

Reported
...
from typing import Any
...
def __eq__(self, other: Any) -> bool:
return True
from typing import TypeVar
...
python:
lint:
rules:
any-eq-parameter: warn # off (default), warn, error

Enabled by the presets: python/ruff.

Suppress one line with sudsy-disable-next-line any-eq-parameter in a comment of the file’s language.

The same check in other tools; Sudsy reports what each upstream rule reports.

Tool Rule Match
ruff PYI032 full