Skip to content

BUG: NDArray[Any] methods ignore overload ambiguity #20099

Closed

Description

@vnmabus

Describe the issue:

A operation between a NDArray[Any] array and an integer, as in the code example, makes Mypy infer the result as
numpy.ndarray[Any, numpy.dtype[numpy.signedinteger[Any]]]. This is an error, as the result could also be a floating point array, or even a complex one.

Reproduce the code example:

from numpy.typing import NDArray

def f(arr: NDArray[Any]) -> None:
    reveal_type(arr + 2)

Error message:

No response

NumPy/Python version information:

1.21.2 3.7.6 (default, Jan 8 2020, 19:59:22)
[GCC 7.3.0]

Activity

  1. changed the title [-]BUG: Operation with integer type changes the dtype inferred by mypy to signedinteger[/-] [+]BUG: `NDArray[Any]` methods ignore overload ambiguity[/+] on Oct 27, 2021
  2. BvB93 commented on Nov 1, 2021

    @BvB93
    Member

    cc @nschloe

    Turns out this issue is present in both mypy and pyright: #20265

  3. BvB93 commented on Nov 1, 2021

    @BvB93
    Member

    For Pyright I opened an issue at microsoft/pyright#2521.

    It seems that Pyright currently does not handle overload ambiguity at all,
    so I'm concerned this might be more difficult to fix compared to python/mypy#11347.

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

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