Skip to content

fix: forward generator return value through the trampoline - #542

Merged
boxed merged 1 commit into
boxed:mainfrom
Sanjays2402:fix/trampoline-generator-return-value
Jul 31, 2026
Merged

fix: forward generator return value through the trampoline#542
boxed merged 1 commit into
boxed:mainfrom
Sanjays2402:fix/trampoline-generator-return-value

Conversation

@Sanjays2402

Copy link
Copy Markdown
Contributor

Closes #540

The generator branch of wrap_in_trampoline used a bare yield from trampoline(...), so the wrapper generator always ended with an implicit None. A caller doing result = yield from decorated_gen() lost the generator's return value, making tests that assert on it fail under mutmut run while passing under plain pytest. Returning the delegation result matches the PEP 380 expansion, mirroring the equivalent fix already made for async generators in #525.

Added a returning generator plus original/mutated regression tests to tests/mutation/test_trampoline.py; both fail on the current code and pass with the fix.

This change was prepared with AI assistance; the regression test was run locally and fails without the fix.

wrap_in_trampoline's generator branch used a bare "yield from
trampoline(...)", so the wrapper generator always finished with an
implicit None. A caller doing "result = yield from decorated_gen()"
therefore got None instead of the generator's return value, and any
test asserting on that value failed under "mutmut run" while passing
under plain pytest.

Returning the delegation result matches the PEP 380 expansion and
mirrors the equivalent fix already applied to the async-generator
branch.

Adds a returning generator to the trampoline test module plus original
and mutated regression tests that consume it with "yield from".
@boxed
boxed merged commit 0092be2 into boxed:main Jul 31, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

isgeneratorfunction branch in wrap_in_trampoline always returns None

2 participants