Open
Conversation
- decorator allows using *args and **kwargs for default args, while keeping dynamic and static type signature the same - moved trampoline inside of mutmut code, instead of generating it as string - unified handling of normal class methods, @staticmethod, @classmethod and enums (always dictionary outside, and methods inside class body)
- ignore mutmut trampoline - ignore 3rd party library frames
nicklafleur
approved these changes
May 3, 2026
Collaborator
There was a problem hiding this comment.
one extremely minor nit, otherwise I really really like the design of this, reads much more clean than what I came up with!
It's not immediately obvious to me where the stack tracking will fit in for the cache invalidation, but I'm sure that there's some options as far as reflection goes in the decorator that we can work with so it should be more than possible just a matter of rebasing and giving it a shot (I should have time to try it out this week).
| trampoline templates are resilient to forward references when using the external trampoline | ||
| pattern. | ||
| """ | ||
| async def async_get_all() -> AsyncGenerator["Color", None]: |
Collaborator
There was a problem hiding this comment.
Suggested change
| async def async_get_all() -> AsyncGenerator["Color", None]: | |
| async def async_get_all() -> AsyncGenerator[Color, None]: |
The unquoted Color here is a meaningful test signal for handling unquoted py3.10 forward references
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR makes following changes:
@_mutmut_mutateddecorator as a trampoline. This allows using *args and **kwargs for default args, whilekeeping dynamic and static type signature the same (fixes Fix default argument mutation #477 )
@staticmethod,@classmethodand enums (always put dictionary outside the class body, and methods inside class body)
source_pathscode (fixes Only count user-code frames formax_stack_depth#378 )The test_mutation_regression.py test shows how the mutation changed. Now it's like this:
becomes
Overall I'm pretty happy with this design, as it works for everything we support currently (normal class methods,
@staticmethod,@classmethodand enum). For the@classmethod, we need to have some special handling s.t. we call the method bound to theclsclass (seeis_classmethodin trampoline.py). Apart from that the trampoline only passes the args and kwargs to the appropriate original/mutated method.@nicklafleur As you already know this part of the code, happy for feedback. Also if something you want to build on top of this would not work with this design, let me know :)
And the runtime tests are pretty handy ❤️