Skip to content

Should object.__hash__ be Callable[[], int] | None if None is a valid and common usage? #6243

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

Open
KotlinIsland opened this issue Nov 5, 2021 · 2 comments

Comments

@KotlinIsland
Copy link
Contributor

Currently you have to type: ignore it.

related: #3884

@srittau
Copy link
Collaborator

srittau commented Nov 5, 2021

Everything we do about __hash__() is problematic, because of its Schrödinger's nature:

class Foo:
    pass
print(Foo().__hash__())  # prints an int

class Bar:
    def __eq__(self, other):
        return True
Bar().__hash__()  # `NoneType` object is not callable

I believe the best solution for this problem is to special-case type checkers so that __hash__: None is a valid construct in stubs and you don't need # type: ignore for that. I commented as such on python/mypy#11465.

@sobolevn
Copy link
Member

sobolevn commented Nov 9, 2021

Related python/mypy#11495

ftynse pushed a commit to llvm/llvm-project that referenced this issue Mar 31, 2022
This commit fixes or disables all errors reported by

    python3 -m mypy -p mlir --show-error-codes

Note that unhashable types cannot be currently expressed in a way compatible
with typeshed. See python/typeshed#6243 for details.

Reviewed By: ftynse

Differential Revision: https://reviews.llvm.org/D122790
mem-frob pushed a commit to draperlaboratory/hope-llvm-project that referenced this issue Oct 7, 2022
This commit fixes or disables all errors reported by

    python3 -m mypy -p mlir --show-error-codes

Note that unhashable types cannot be currently expressed in a way compatible
with typeshed. See python/typeshed#6243 for details.

Reviewed By: ftynse

Differential Revision: https://reviews.llvm.org/D122790
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants