88import libcst as cst
99from libcst .metadata import PositionProvider , MetadataWrapper
1010import libcst .matchers as m
11- from mutmut .trampoline_templates import build_trampoline , mangle_function_name , trampoline_impl , yield_from_trampoline_impl
11+ from mutmut .trampoline_templates import build_trampoline , mangle_function_name , trampoline_impl
1212from mutmut .node_mutation import mutation_operators , OPERATORS_TYPE
1313
1414NEVER_MUTATE_FUNCTION_NAMES = { "__getattribute__" , "__setattr__" , "__new__" }
@@ -165,8 +165,6 @@ def _skip_node_and_children(self, node: cst.CSTNode):
165165# convert str trampoline implementations to CST nodes with some whitespace
166166trampoline_impl_cst = list (cst .parse_module (trampoline_impl ).body )
167167trampoline_impl_cst [- 1 ] = trampoline_impl_cst [- 1 ].with_changes (leading_lines = [cst .EmptyLine (), cst .EmptyLine ()])
168- yield_from_trampoline_impl_cst = list (cst .parse_module (yield_from_trampoline_impl ).body )
169- yield_from_trampoline_impl_cst [- 1 ] = yield_from_trampoline_impl_cst [- 1 ].with_changes (leading_lines = [cst .EmptyLine (), cst .EmptyLine ()])
170168
171169
172170def combine_mutations_to_source (module : cst .Module , mutations : Sequence [Mutation ]) -> tuple [str , Sequence [str ]]:
@@ -185,7 +183,6 @@ def combine_mutations_to_source(module: cst.Module, mutations: Sequence[Mutation
185183
186184 # trampoline functions
187185 result .extend (trampoline_impl_cst )
188- result .extend (yield_from_trampoline_impl_cst )
189186
190187 mutations_within_function = group_by_top_level_node (mutations )
191188
@@ -234,7 +231,6 @@ def function_trampoline_arrangement(function: cst.FunctionDef, mutants: Iterable
234231
235232 name = function .name .value
236233 mangled_name = mangle_function_name (name = name , class_name = class_name ) + '__mutmut'
237- _is_generator = is_generator (function )
238234
239235 # copy of original function
240236 nodes .append (function .with_changes (name = cst .Name (mangled_name + '_orig' )))
@@ -248,7 +244,7 @@ def function_trampoline_arrangement(function: cst.FunctionDef, mutants: Iterable
248244 nodes .append (mutated_method ) # type: ignore
249245
250246 # trampoline that forwards the calls
251- trampoline = list (cst .parse_module (build_trampoline (orig_name = name , mutants = mutant_names , class_name = class_name , is_generator = _is_generator )).body )
247+ trampoline = list (cst .parse_module (build_trampoline (orig_name = name , mutants = mutant_names , class_name = class_name )).body )
252248 trampoline [0 ] = trampoline [0 ].with_changes (leading_lines = [cst .EmptyLine ()])
253249 nodes .extend (trampoline )
254250
@@ -274,28 +270,6 @@ def group_by_top_level_node(mutations: Sequence[Mutation]) -> Mapping[cst.CSTNod
274270
275271 return grouped
276272
277- def is_generator (function : cst .FunctionDef ) -> bool :
278- """Return True if the function has yield statement(s)."""
279- visitor = IsGeneratorVisitor (function )
280- function .visit (visitor )
281- return visitor .is_generator
282-
283- class IsGeneratorVisitor (cst .CSTVisitor ):
284- """Check if a function is a generator.
285- We do so by checking if any child is a Yield statement, but not looking into inner function definitions."""
286- def __init__ (self , original_function : cst .FunctionDef ):
287- self .is_generator = False
288- self .original_function : cst .FunctionDef = original_function
289-
290- def visit_FunctionDef (self , node ):
291- # do not recurse into inner function definitions
292- if self .original_function != node :
293- return False
294-
295- def visit_Yield (self , node ):
296- self .is_generator = True
297- return False
298-
299273def pragma_no_mutate_lines (source : str ) -> set [int ]:
300274 return {
301275 i + 1
0 commit comments