<s> """<STR_LIT>""" <EOL> from nuitka . optimizations . Optimization import areEmptyTraces <EOL> from . FinalizeBase import FinalizationVisitorBase <EOL> class FinalizeClosureTaking ( FinalizationVisitorBase ) : <EOL> def onEnterNode ( self , node ) : <EOL> for variable in node . getClosureVariables ( ) : <EOL> assert not variable . isModuleVariable ( ) <EOL> current = node <EOL> while current is not variable . getOwner ( ) : <EOL> if current . isParentVariableProvider ( ) : <EOL> if variable not in current . getClosureVariables ( ) : <EOL> current . addClosureVariable ( variable ) <EOL> assert current . getParentVariableProvider ( ) is not current <EOL> current = current . getParentVariableProvider ( ) <EOL> assert current is not None , variable <EOL> class FinalizeClassClosure ( FinalizationVisitorBase ) : <EOL> def onEnterNode ( self , function_body ) : <EOL> for closure_variable in function_body . getClosureVariables ( ) : <EOL> if closure_variable . getName ( ) not in ( "<STR_LIT>" , "<STR_LIT>" ) : <EOL> continue <EOL> variable_traces = function_body . constraint_collection . getVariableTraces ( <EOL> variable = closure_variable <EOL> ) <EOL> empty = areEmptyTraces ( variable_traces ) <EOL> if empty : <EOL> function_body . removeClosureVariable ( closure_variable ) </s>
