python / python/mypy

`in` operator error with Generator

Open
#21,601 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Python
Stars
20.6k
Forks
3.3k
PR merge metrics
PR metrics pending

Description

Bug Report
https://mypy-play.net/?mypy=latest&python=3.12&gist=790ec23819f191c250a9574f2b123d8d

To Reproduce

1 in (i for i in (signal.SIGINT,))

Expected Behavior
No error

Actual Behavior
error: Unsupported operand types for in ("int" and "Generator[Signals, None, None]") [operator]

If the generator is changed to a list comprehension, there is no error

Your Environment

  • Mypy version used: 2.1.0 and master branch
  • Python version used: 3.12

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the mypy-play reproduction from the issue with Python 3.12, then trace how mypy checks the in operator when the right-hand side is a generator. Add a regression test covering the shown signal.SIGINT expression; done means it produces no unsupported-operand error while the existing list-comprehension behavior remains unchanged.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
58/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.