Skip to content

TYP: np.maximum(np.array(1), np.array(1)) is Any in 2.2.2 while it wasn't in 2.2.1 #28193

Closed as duplicate

Description

@bersbersbers

Describe the issue:

numpy 2.2.2 reveals a different type for np.maximum(np.array(1), np.array(1)) than 2.2.1. This looks like a result of #28176. In contrast to #28192, which I think may be intended, I think this is unintended behavior.

This happens only with mypy, not pyright.

Reproduce the code example:

from typing import reveal_type

import numpy as np

reveal_type(np.maximum(np.array(1), np.array(1)))

Error message:

2.2.2: Revealed type is "Any"
2.2.1: Revealed type is "numpy.ndarray[builtins.tuple[builtins.int, ...], numpy.dtype[Any]]"

Python and NumPy Versions:

Numpy 2.2.2 vs 2.2.1

Type-checker version and settings:

mypy 1.14.1 (compiled: yes)

Additional typing packages.

No response

Activity

  1. jorenham commented on Jan 20, 2025

    @jorenham
    Member

    I think this is actually the same underlying problem as #28192, because

    reveal_type(np.array(1))

    is reported as

    Revealed type is "ndarray[tuple[int, ...], dtype[Any]]"
    

    Note that both np.maximum and the np.mod from #28192 are instances of the same (type-check-only) _UFunc_Nin2_Nout type.

    The 0-d arrays are not scalars, so the first _UFunc_Nin2_Nout.__call__ overload also isn't relevant. And just like in #28192, it's only mypy that infers Any, and pyright reports the following:

    Type of "np.maximum(np.array(1), np.array(1))" is "ndarray[tuple[int, ...], dtype[Any]]"
    
  2. bersbersbers commented on Jan 21, 2025

    @bersbersbers
    ContributorAuthor
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