Coverage for src / renaissance / recipes / cleanup_refactoring.py: 100%
11 statements
« prev ^ index » next coverage.py v7.13.4, created at 2026-09-09 14:04 +0000
« prev ^ index » next coverage.py v7.13.4, created at 2026-09-09 14:04 +0000
1from more_itertools import flatten
3from renaissance.integrations.types import CompoundStatement, VariableDef
4from renaissance.syntax_tree import ASTProcessor
5from renaissance.syntax_tree.ast_finder import find_ast_type
8class CleanupRefactoring:
9 def __init__(self):
10 raise Exception("This class should not be instantiated")
12 @staticmethod
13 def remove_unused_variables(ast_refactor: ASTProcessor) -> None:
14 """Removes all unused variables from a function."""
15 refs = flatten(find_ast_type(n, VariableDef) for n in find_ast_type(ast_refactor.node, CompoundStatement))
16 [ast_refactor.remove(ref.parent, True, True) for ref in refs if len(ref.referenced_by) == 0]