Skip to content

[1.12 regression] False positive when iterating over union #17945

Closed

Description

@hauntsaninja
import itertools

def foo(arg: int | None):
    it = itertools.count() if arg is None else range(arg)
    for i in it:
        print(i)

Now gives:

test40.py:5: error: Item "range" of "range | Iterator[int]" has no attribute "__next__"  [union-attr]

The proximal cause is probably the switch away from unions in ternary

Activity

  1. changed the title [-][1.12 regression][/-] [+][1.12 regression] False positive when iterating over union[/+] on Oct 14, 2024
  2. added a commit that references this issue on Oct 16, 2024
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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions