Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

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

Closed
hauntsaninja opened this issue Oct 14, 2024 · 0 comments · Fixed by #17976
Closed

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

hauntsaninja opened this issue Oct 14, 2024 · 0 comments · Fixed by #17976
Labels
bug mypy got something wrong good-second-issue

Comments

@hauntsaninja
Copy link
Collaborator

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

@hauntsaninja hauntsaninja added the bug mypy got something wrong label Oct 14, 2024
@hauntsaninja hauntsaninja changed the title [1.12 regression] [1.12 regression] False positive when iterating over union Oct 14, 2024
hauntsaninja added a commit to hauntsaninja/mypy that referenced this issue Oct 16, 2024
hauntsaninja added a commit to hauntsaninja/mypy that referenced this issue Oct 18, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug mypy got something wrong good-second-issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant