Thanks to visit codestin.com
Credit goes to github.com

Skip to content

TYP: np.dtype is not Hashable #24621

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
twoertwein opened this issue Sep 2, 2023 · 0 comments · Fixed by #24623
Closed

TYP: np.dtype is not Hashable #24621

twoertwein opened this issue Sep 2, 2023 · 0 comments · Fixed by #24623

Comments

@twoertwein
Copy link

Describe the issue:

Pyright (and python) infer np.dtype (and other sub-classes of np._ArrayOrScalarCommon) as not Hashable as they overwrite __eq__ without overwriting __hash__.

xref microsoft/pyright#5878

Reproduce the code example:

from typing import Hashable
import numpy as np

def test(x: Hashable) -> None: ...

def foo() -> np.dtype: ...

test(foo())

Error message:

error: Argument of type "dtype[Unknown]" cannot be assigned to parameter "x" of type "Hashable" in function "test"
    "dtype[Unknown]" is incompatible with protocol "Hashable"
      "__hash__" is an incompatible type
        Type "None" cannot be assigned to type "(self: dtype[Unknown]) -> int" (reportGeneralTypeIssues)

Runtime information:

>>> import sys, numpy; print(numpy.__version__); print(sys.version)
1.24.4
3.11.4 (main, Jun 14 2023, 18:15:32) [GCC 12.2.0]
>>> print(numpy.show_runtime())
WARNING: `threadpoolctl` not found in system! Install it by `pip install threadpoolctl`. Once installed, try `np.show_runtime` again for more detailed build information
[{'simd_extensions': {'baseline': ['SSE', 'SSE2', 'SSE3'],
                      'found': ['SSSE3',
                                'SSE41',
                                'POPCNT',
                                'SSE42',
                                'AVX',
                                'F16C',
                                'FMA3',
                                'AVX2'],
                      'not_found': ['AVX512F',
                                    'AVX512CD',
                                    'AVX512_KNL',
                                    'AVX512_KNM',
                                    'AVX512_SKX',
                                    'AVX512_CLX',
                                    'AVX512_CNL',
                                    'AVX512_ICL']}}]
None

Context for the issue:

No response

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

Successfully merging a pull request may close this issue.

2 participants