Skip to content

FOO and next(iter(FOO)) #10696

Open
Open

Description

@dimaqq

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
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

    bugmypy got something wrongtopic-type-contextType context / bidirectional inference

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions