uppercase constant, don't change order of decorators
@@ -5,10 +5,12 @@ from .operator import Operator
class RemoveDecorator(Operator):
"""An operator that removes each of the non standard decorators."""
- regular_decorators = frozenset(["classmethod", "staticmethod", "abstractmethod"])
+ REGULAR_DECORATORS = frozenset(["classmethod", "staticmethod",
+ "abstractmethod"])
def visit_FunctionDef(self, node): # noqa
- decorator_candidates = [x for x in node.decorator_list if x.id not in self.regular_decorators]
+ decorator_candidates = [x for x in node.decorator_list
+ if x.id not in self.REGULAR_DECORATORS]
if decorator_candidates:
return self.visit_mutation_site(node, len(decorator_candidates))
@@ -16,9 +18,8 @@ class RemoveDecorator(Operator):
def mutate(self, node, idx):
"""Modify the decorator list to remove one decorator at each mutation"""
- decorator_candidates = [x for x in node.decorator_list if x.id not in self.regular_decorators]
- del decorator_candidates[idx]
- modified_decorator = decorator_candidates + [x for x in node.decorator_list if x.id in self.regular_decorators]
- node.decorator_list = modified_decorator
-
+ candidates = [(i, d) for (i,d) in enumerate(node.decorator_list)
+ if d.id not in self.REGULAR_DECORATORS]
+ remove_idx, _ = candidates[idx]
+ del node.decorator_list[remove_idx]
return node
