Skip to content

BUG: In "numpy/__init__.pyi", type dtype referenced in ndarray.item(...) needs to be aliased #20223

@Azureblade3808

Description

@Azureblade3808

Describe the issue:

I found that the result type of ndarray.item(...) cannot be correctly inferred by Pylance, but mypy seems to work well. And I believe that the problem is caused by dtype referenced in the signature of ndarray.item(...) being shadowed by ndarray.dtype which is a property.

According to the response of Pylance maintainers (see microsoft/pylance-release#1999), dtype here needs to be aliased, and mypy is wrong in this case.

Reproduce the code example:

from typing import Any
import numpy as np

def return_any() -> Any: ...

a: np.ndarray[Any, np.dtype[np.float_]] = return_any()
b = a.item()

# Type of `b` cannot be inferred by Pylance, because `dtype` in
# the signature of `ndarray.item(...)` doesn't match `np.dtype`.

Error message:

No response

NumPy/Python version information:

I'm using Numpy v1.21.2.

Python version is irrelevant because this is a type stubs issue.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions