Skip to content

__hash__ = None in class definition should not emit assignment error #16954

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

Closed
starhel opened this issue Feb 27, 2024 · 1 comment
Closed

__hash__ = None in class definition should not emit assignment error #16954

starhel opened this issue Feb 27, 2024 · 1 comment
Labels
bug mypy got something wrong

Comments

@starhel
Copy link

starhel commented Feb 27, 2024

Bug Report
To suppress hash support in a class, it's recommended to include __hash__ = None in the class definition (it's also required by the ruff rule PLW1641). Unfortunately, mypy reports it as an error.

error: Incompatible types in assignment (expression has type "None", base class "object" defined the type as "Callable[[object], int]")  [assignment]

To Reproduce
https://mypy-play.net/?mypy=latest&python=3.12&gist=2f1c3fd7eff039975b0203c916d75002

class A:
    __hash__ = None

    def __init__(self, x):
        self.x = x

a = A(10)
@starhel starhel added the bug mypy got something wrong label Feb 27, 2024
@JukkaL
Copy link
Collaborator

JukkaL commented Mar 18, 2024

Closing as duplicate of #4266.

@JukkaL JukkaL closed this as completed Mar 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong
Projects
None yet
Development

No branches or pull requests

2 participants