diff --git a/src/mutmut/file_mutation.py b/src/mutmut/file_mutation.py index 2fa50ba6..77f39403 100644 --- a/src/mutmut/file_mutation.py +++ b/src/mutmut/file_mutation.py @@ -248,7 +248,7 @@ def function_trampoline_arrangement(function: cst.FunctionDef, mutants: Iterable nodes.append(mutated_method) # type: ignore # trampoline that forwards the calls - trampoline = list(cst.parse_module(build_trampoline(orig_name=name, mutants=mutant_names, class_name=class_name)).body) + trampoline = list(cst.parse_module(build_trampoline(orig_name=name, mutants=mutant_names, class_name=class_name, asynchronous=function.asynchronous)).body) trampoline[0] = trampoline[0].with_changes(leading_lines=[cst.EmptyLine()]) nodes.extend(trampoline) diff --git a/src/mutmut/trampoline_templates.py b/src/mutmut/trampoline_templates.py index ad4cc90a..3c6fa1bb 100644 --- a/src/mutmut/trampoline_templates.py +++ b/src/mutmut/trampoline_templates.py @@ -1,6 +1,6 @@ CLASS_NAME_SEPARATOR = 'ǁ' -def build_trampoline(*, orig_name, mutants, class_name): +def build_trampoline(*, orig_name, mutants, class_name, asynchronous): mangled_name = mangle_function_name(name=orig_name, class_name=class_name) mutants_dict = f'{mangled_name}__mutmut_mutants : ClassVar[MutantDict] = {{\n' + ', \n '.join(f'{repr(m)}: {m}' for m in mutants) + '\n}' @@ -17,8 +17,8 @@ def build_trampoline(*, orig_name, mutants, class_name): return f""" {mutants_dict} -def {orig_name}({'self, ' if class_name is not None else ''}*args, **kwargs): - result = {trampoline_name}({access_prefix}{mangled_name}__mutmut_orig{access_suffix}, {access_prefix}{mangled_name}__mutmut_mutants{access_suffix}, args, kwargs{self_arg}) +{'async ' if asynchronous is not None else ''}def {orig_name}({'self, ' if class_name is not None else ''}*args, **kwargs): + result = {'await ' if asynchronous is not None else ''} {trampoline_name}({access_prefix}{mangled_name}__mutmut_orig{access_suffix}, {access_prefix}{mangled_name}__mutmut_mutants{access_suffix}, args, kwargs{self_arg}) return result {orig_name}.__signature__ = _mutmut_signature({mangled_name}__mutmut_orig)