mypy infers `Any` for numpy 2.2.2. expressions that worked with 2.2.1
Open
Nobody has claimed this yet.
bug
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
Bug Report
mypy infers Any for several numpy expressions after upgrading to numpy==2.2.2
See also
- https://github.com/numpy/numpy/issues/28193
- https://github.com/numpy/numpy/issues/28192
- https://github.com/numpy/numpy/pull/28176
To Reproduce
from typing import reveal_type
import numpy as np
reveal_type(np.maximum(np.array(1), np.array(1)))
Expected Behavior
ndarray[tuple[int, ...], dtype[Any]]
Actual Behavior
Any
Your Environment
This works with numpy==2.2.1; also, it works with pyright. So it seems to be specific to numpy==2.2.2 and mypy.
- Mypy version used: mypy 1.14.1 (compiled: yes)
- Mypy command-line flags: none
- Mypy configuration options from
mypy.ini(and other config files): none - Python version used: 3.13.1
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running the provided reveal_type example with mypy 1.14.1 against numpy 2.2.1 and 2.2.2, then compare the related NumPy issues and pull request. Trace why the expression becomes Any and verify that the inferred type is restored without regressing the working version.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- numpy, python
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100