Incorrect send type with `yield from`
Open
Nobody has claimed this yet.
bug
topic-runtime-semantics
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
Bug Report
Generators do not respect the send type when using yield from.
To Reproduce
def foo() -> Generator[None, int, None]:
x: int = yield
def bar() -> Generator[None, str, None]:
yield from foo()
Expected Behavior
Should error on yield from foo().
Actual Behavior
Does not error and allows gen = bar(); gen.send("abc"), which results in x: int = "abc".
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running the Python reproduction in the issue and trace how mypy checks generator send types through yield from. Add a regression test covering foo() and bar(), and confirm that mypy reports an error at yield from foo() rather than allowing a string to be sent to the integer-typed generator.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100