GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — mypy infers `numpy.float64` instead of `Any` for `numpy.ndarray.__iter__` in numpy 2.2.2 · Issue #18566 · python/mypy

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

New issue
Copy link
New issue
Copy link
Closed as duplicate
Closed as duplicate
mypy infers numpy.float64 instead of Any for numpy.ndarray.__iter__ in numpy 2.2.2#18566
Copy link
Labels
bugmypy got something wrongtopic-overloads

Description

@matteobrv
matteobrv
opened on Jan 29, 2025
Issue body actions

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
Reacted by Joren Hammudoglu

Activity

  1. matteobrv
    added
    bugmypy got something wrong
    on Jan 29, 2025
  2. A5rocks
    added
    topic-overloads
    on Jan 29, 2025
  3. cdce8p
    added a parent issue on Jan 30, 2025
    • Issues related to numpy #18343
  4. github-project-automation
    added this to GC-Content-Calculatoron Dec 12, 2025
  5. github-project-automation
    moved this to Todo in GC-Content-Calculatoron Dec 12, 2025
  6. ilevkivskyi commented on Sep 19, 2026

    @ilevkivskyi
    ilevkivskyi
    on Sep 19, 2026
    Member
    More actions

    I just tried this with numpy 2.3.2 and a recent mypy master, and I cannot reproduce this, i.e. I get an Any as expected. I guess there is some workaround in place. Do you have a (preferably simple) standalone repro? cc @jorenham

  7. jorenham commented on Sep 19, 2026

    @jorenham
    jorenham
    on Sep 19, 2026
    Contributor
    More actions

    I also cannot reproduce this anymore with the latest mypy and NumPy (2.5.3):

    Image
  8. ilevkivskyi commented on Sep 19, 2026

    @ilevkivskyi
    ilevkivskyi
    on Sep 19, 2026
    Member
    More actions

    I guess this was "fixed" by numpy/numpy#29218. After looking a bit more, it seems to be the underlying cause is #11347, so I am going to close this one as a duplicate.

  9. ilevkivskyi
    closed this as a duplicateof Overload ambiguity is ignored in self-annotated methods #11347 on Sep 19, 2026
  10. jorenham commented on Sep 19, 2026

    @jorenham
    jorenham
    on Sep 19, 2026
    Contributor
    More actions

    I guess this was "fixed" by numpy/numpy#29218. After looking a bit more, it seems to be the underlying cause is #11347, so I am going to close this one as a duplicate.

    Ah yea I forgot about that 9-dimensional "workaroundaround" haha

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrongtopic-overloads

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402775 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.