8000 TYPING: `_64Bit` reported as incompatible with `NBitBase` · Issue #24569 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content
TYPING: _64Bit reported as incompatible with NBitBase #24569
Closed
@bersbersbers

Description

@bersbersbers

Describe the issue:

mypy reports an error in the following code. Comparing ndarray[Any, dtype[signedinteger[_64Bit]]] and ndarray[Any, dtype[signedinteger[NBitBase]]], the only difference seems to be _64Bit vs. NBitBase - although the former is a subclass of the latter:

class _256Bit(NBitBase): # type: ignore[misc]
pass
class _128Bit(_256Bit): # type: ignore[misc]
pass
class _96Bit(_128Bit): # type: ignore[misc]
pass
class _80Bit(_96Bit): # type: ignore[misc]
pass
class _64Bit(_80Bit): # type: ignore[misc]
pass

Reproduce the code example:

import numpy as np
import numpy.typing as npt

def fun(array: npt.NDArray[np.bool_]) -> npt.NDArray[np.signedinteger[npt.NBitBase]]:
    return np.flatnonzero(array)

Error message:

C:\Code\project>mypy bug.py
bug.py:5: error: Incompatible return value type (got "ndarray[Any, dtype[signedinteger[_64Bit]]]", expected "ndarray[Any, dtype[signedinteger[NBitBase]]]")  [return-value]
Found 1 error in 1 file (checked 1 source file)

Runtime information:

1.25.2
3.11.5 (tags/v3.11.5:cce6ba9, Aug 24 2023, 14:38:34) [MSC v.1936 64 bit (AMD64)]

Context for the issue:

I had to choose between reporting this at mypy or here first. Hope I made a decent choice, but I am happy to report elsewhere as well.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0