Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(📚) docs for PLW1641 known problems doesn't make sense #14883

Closed
KotlinIsland opened this issue Dec 9, 2024 · 6 comments · Fixed by #14885
Closed

(📚) docs for PLW1641 known problems doesn't make sense #14883

KotlinIsland opened this issue Dec 9, 2024 · 6 comments · Fixed by #14885
Labels
documentation Improvements or additions to documentation

Comments

@KotlinIsland
Copy link
Contributor

KotlinIsland commented Dec 9, 2024

# Known problems
Does not check for `__hash__` implementations in superclasses.

__hash__ defined in a superclass doesn't affect the semantics:

class A:
    def __hash__(self):
        return 1

class B(A):
   def __eq__(self, other):
       return False
B.__hash__ # None
@zanieb
Copy link
Member

zanieb commented Dec 9, 2024

The rule is

Checks for classes that implement __eq__ but not __hash__.

So.. if you have this:

class A:
    def __hash__(self):
        return 1

class B(A):
   def __eq__(self, other):
       return False

B implements __hash__ via A but is not detected by Ruff.

What doesn't make sense about this?

@KotlinIsland
Copy link
Contributor Author

What doesn't make sense about this?

as in my OP:

print(B.__hash__) # None

@KotlinIsland
Copy link
Contributor Author

KotlinIsland commented Dec 10, 2024

A class that overrides eq() and does not define hash() will have its hash() implicitly set to None.

source: https://docs.python.org/3/reference/datamodel.html#object.__hash__

@charliermarsh
Copy link
Member

Wow, so it's just when __eq__ is defined?

@zanieb
Copy link
Member

zanieb commented Dec 10, 2024

@KotlinIsland sorry your OP doesn't have inheritance

Interesting find though!

@zanieb zanieb added the documentation Improvements or additions to documentation label Dec 10, 2024
@KotlinIsland
Copy link
Contributor Author

KotlinIsland commented Dec 10, 2024

sorry your OP doesn't have inheritance

fail...

i've updated it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants