Skip to content

mypy infers numpy.float64 instead of Any for numpy.ndarray.__iter__ in numpy 2.2.2 #18566

@matteobrv

Description

@matteobrv

Bug Report

It looks like mypy doesn't correctly handle the overloading of numpy.ndarray.__iter__. In the example below mypy infers numpy.float64 for ai while the correct type is Any.

See also: numpy/numpy#28245

To Reproduce

import numpy as np
import numpy.typing as npt

a: npt.NDArray[np.float64] = np.ones([2, 2])

for _, ai in enumerate(a):
    reveal_type(ai)

Expected Behavior

Any

Actual Behavior

test.py:7: note: Revealed type is "numpy.float64"

Your Environment

Both pyright 1.1.392 and basedpyright 1.25.0 behave as expected.

  • 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.12.8 (main, Jan 22 2025, 21:56:05) [GCC 11.4.0]
  • Numpy version used: 2.2.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy