Skip to content

any-eq-ne-annotation (PYI032)#

Derived from the flake8-pyi linter.

Fix is always available.

What it does#

Checks for __eq__ and __ne__ implementations that use typing.Any as the type annotation for the obj parameter.

Why is this bad?#

The Python documentation recommends the use of object to "indicate that a value could be any type in a typesafe manner", while Any should be used to "indicate that a value is dynamically typed."

The semantics of __eq__ and __ne__ are such that the obj parameter should be any type, as opposed to a dynamically typed value. Therefore, the object type annotation is more appropriate.

Example#

class Foo:
    def __eq__(self, obj: typing.Any):
        ...

Use instead:

class Foo:
    def __eq__(self, obj: object):
        ...

References#