Skip to content

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

@hauntsaninja

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions