Skip to content

Mypy incorrectly requires __next__() on the iterable of a for loop (regression from 0.942). #16733

Description

@md2468

Bug Report

For loops in Python require only an iterable, for which an iterator is subsequently created. However, in the code below, Mypy incorrectly requires __next__ to be available on the iterable.

To Reproduce

from collections.abc import Iterable

xs: zip[tuple[object, ...]] | Iterable[object] = zip(*[[0], [0]])
for x in xs: pass

Actual Behavior

main.py:4: error: "Iterable[object]" has no attribute "__next__"  [attr-defined]

Your Environment

  • Mypy version used: 1.8.0.
  • Mypy command-line flags: None.
  • Mypy configuration options from mypy.ini (and other config files): None.
  • Python version used: 3.12.

This is a regression from version 0.942.
1.8.0 Playground
0.942 Playground

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrong

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions