Skip to content

Conversation

@DamienGR
Copy link
Owner

This commit fixes the issue where mutmut 3.4.0 generates synchronous wrapper trampolines for async functions, which breaks frameworks like FastAPI that use asyncio.iscoroutinefunction() to inspect function signatures.

Changes:

  • Added is_async and is_async_generator parameters to build_trampoline()
  • Created _mutmut_trampoline_async() for async functions that properly awaits the original/mutant functions
  • Async generators now use a wrapper that yields from the original async generator to preserve async iteration behavior
  • Added _contains_yield() helper to detect generator functions
  • Updated tests to handle whitespace changes in generated code

The fix ensures:

  • asyncio.iscoroutinefunction() returns True for async function wrappers
  • Async generators work correctly with 'async for' iteration
  • Regular sync functions continue to work as before

Fixes boxed#454

This commit fixes the issue where mutmut 3.4.0 generates synchronous
wrapper trampolines for async functions, which breaks frameworks like
FastAPI that use asyncio.iscoroutinefunction() to inspect function
signatures.

Changes:
- Added is_async and is_async_generator parameters to build_trampoline()
- Created _mutmut_trampoline_async() for async functions that properly
  awaits the original/mutant functions
- Async generators now use a wrapper that yields from the original
  async generator to preserve async iteration behavior
- Added _contains_yield() helper to detect generator functions
- Updated tests to handle whitespace changes in generated code

The fix ensures:
- asyncio.iscoroutinefunction() returns True for async function wrappers
- Async generators work correctly with 'async for' iteration
- Regular sync functions continue to work as before

Fixes boxed#454

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@DamienGR DamienGR merged commit 2574139 into main Dec 17, 2025
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.

Async functions get synchronous trampolines causing "coroutine was never awaited" errors

2 participants