Skip to content

PLW1641: false positive #20821

@chirizxc

Description

@chirizxc

The current eq-without-hash (PLW1641) rule warns whenever a class defines __eq__ without defining __hash__. However, this creates false positives for legitimate use cases.

Not all classes with __eq__ are intended to be used as dictionary keys or set members. For mutable objects, having __hash__ = None is actually the correct behavior according to Python's data model:
Image

Consider the inverse check instead: warn when a class defines __hash__ (and it's not None) but doesn't define __eq__. This would catch cases where the hash/equality contract is violated: objects that are equal must have the same hash value.

Playground*

Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionAsking for support or clarification

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions