Refactor trampoline setup#514
Conversation
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).
I'd see two possibilities:
Both seem reasonable approaches to me, the first one maybe a bit simpler. |
- 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
The PR #513 used os.path.realpath for this. I think pathlib.Path.resolve() should also work fine, and we can keep using pathlib.Path. Using strict=True, as all files/directories should exist.
757c616 to
dd66f3a
Compare
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 ❤️