Skip to content

TYP: [2.4.0rc1 regression] np.generic no longer Hashable #30445

@inducer

Description

@inducer

Describe the issue:

The code below passes without error when using numpy 2.3.5, but gives the error message below on 2.4.0rc1.

cc @alexfikl

Reproduce the code example:

from typing import Hashable

import numpy as np


def f(x: np.generic) -> Hashable:
    return x

Error message:

/home/andreas/tmp/tnumpy.py:7:12 - error: Type "generic[Any]" is not assignable to return type "Hashable"
    "generic[Any]" is incompatible with protocol "Hashable"
      "__hash__" is an incompatible type
      "__hash__" is not defined as a ClassVar in protocol
        Type "None" is not assignable to type "() -> int" (reportReturnType)
1 error, 0 warnings, 0 notes

Python and NumPy Versions:

Python 3.14.2

Type-checker version and settings:

basedpyright 1.36.1
based on pyright 1.1.407

no settings applied

Additional typing packages.

No response

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions