Skip to content

Commit

Permalink
Fix for generator mutation
Browse files Browse the repository at this point in the history
  • Loading branch information
boxed committed Oct 25, 2024
1 parent 0ba1c7c commit c09c0f3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
4 changes: 2 additions & 2 deletions mutmut/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ def build_trampoline(*, orig_name, mutants, class_name, is_generator):
access_suffix = '")'

if is_generator:
yield_statement = 'yield from'
yield_statement = 'yield from ' # note the space at the end!
trampoline_name = '_mutmut_yield_from_trampoline'
else:
yield_statement = ''
Expand All @@ -324,7 +324,7 @@ def build_trampoline(*, orig_name, mutants, class_name, is_generator):
{mutants_dict}
def {orig_name}({'self, ' if class_name is not None else ''}*args, **kwargs):
result = {yield_statement} {trampoline_name}({access_prefix}{mangled_name}__mutmut_orig{access_suffix}, {access_prefix}{mangled_name}__mutmut_mutants{access_suffix}, *args, **kwargs)
result = {yield_statement}{trampoline_name}({access_prefix}{mangled_name}__mutmut_orig{access_suffix}, {access_prefix}{mangled_name}__mutmut_mutants{access_suffix}, *args, **kwargs)
return result
{orig_name}.__signature__ = _mutmut_signature({mangled_name}__mutmut_orig)
Expand Down
6 changes: 4 additions & 2 deletions tests/test_mutmut3.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ def x_foo__mutmut_2(a, b, c):
}
def foo(*args, **kwargs):
return _mutmut_trampoline(x_foo__mutmut_orig, x_foo__mutmut_mutants, *args, **kwargs)
result = _mutmut_trampoline(x_foo__mutmut_orig, x_foo__mutmut_mutants, *args, **kwargs)
return result
foo.__signature__ = _mutmut_signature(x_foo__mutmut_orig)
x_foo__mutmut_orig.__name__ = 'x_foo'
Expand Down Expand Up @@ -67,7 +68,8 @@ def x_foo__mutmut_1(a: List[int]) -> int:
}
def foo(*args, **kwargs):
return _mutmut_trampoline(x_foo__mutmut_orig, x_foo__mutmut_mutants, *args, **kwargs)
result = _mutmut_trampoline(x_foo__mutmut_orig, x_foo__mutmut_mutants, *args, **kwargs)
return result
foo.__signature__ = _mutmut_signature(x_foo__mutmut_orig)
x_foo__mutmut_orig.__name__ = 'x_foo'
Expand Down

0 comments on commit c09c0f3

Please sign in to comment.