python / python/mypy

mypy infers `Any` for numpy 2.2.2. expressions that worked with 2.2.1

Open
#18,496 2 comments 0 reactions 0 assignees View on GitHub

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

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.