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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
bersbersbers opened this issue Jan 20, 2025 · 2 comments

Comments

@bersbersbers
Copy link
Contributor

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

@jorenham
Copy link
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]]"

@bersbersbers
Copy link
Contributor Author

I opened python/mypy#18496.

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

No branches or pull requests

2 participants