Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

FOO and next(iter(FOO)) #10696

Open
dimaqq opened this issue Jun 23, 2021 · 0 comments
Open

FOO and next(iter(FOO)) #10696

dimaqq opened this issue Jun 23, 2021 · 0 comments
Labels
bug mypy got something wrong topic-type-context Type context / bidirectional inference

Comments

@dimaqq
Copy link

dimaqq commented Jun 23, 2021

Bug Report

Python code

FOO = frozenset("abc")
BAR = FOO and next(iter(FOO))

Mypy reports and error

wtf.py:2: error: Argument 1 to "iter" has incompatible type "FrozenSet[str]"; expected "Iterable[FrozenSet[str]]"

Expected Behavior

Ideally, mypy should infer that type of BAR is "falsey or string".
If not that, then "empty set or string".
if not that, then "set or string".

Actual Behavior

mypy seems to be tripped by X op func(X), gets confused 😖
mypy complains about the argument to iter 🤷🏿

Note that expression like BAR = next(iter(FOO)) is understood correctly.

Your Environment

  • Mypy version used: 0.910
  • Mypy command-line flags: none
  • Mypy configuration options from mypy.ini (and other config files): none
  • Python version used: 3.9.5
  • Operating system and version: macos, universal2
@dimaqq dimaqq added the bug mypy got something wrong label Jun 23, 2021
@hauntsaninja hauntsaninja added the topic-type-context Type context / bidirectional inference label May 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong topic-type-context Type context / bidirectional inference
Projects
None yet
Development

No branches or pull requests

2 participants