a `@s8dZddlmZddlmZddZGdddeZdS) aThe optimizer tries to constant fold expressions and modify the AST in place so that it should be faster to evaluate. Because the AST does not contain all the scoping information and the compiler has to find that out, we cannot do all the optimizations we want. For example, loop unrolling doesn't work because unrolled loops would have a different scope. The solution would be a second syntax tree that stored the scoping rules. )nodes)NodeTransformercCst|}||S)z^The context hint can be used to perform an static optimization based on the context given.) OptimizerZvisit)node environmentZ optimizerr4/usr/lib/python3.9/site-packages/jinja2/optimizer.pyoptimizesr cs$eZdZddZfddZZS)rcCs ||_dS)N)r)selfrrrr__init__szOptimizer.__init__csntt|j|g|Ri|}t|tjrjz*tjj||rB|dnd|j |j dWStj yhYn0|S)N)linenor) superr generic_visit isinstancerZExprZConstZfrom_untrustedZas_constr rZ Impossible)r rargskwargs __class__rrrs zOptimizer.generic_visit)__name__ __module__ __qualname__r r __classcell__rrrrrsrN)__doc__rZvisitorrr rrrrrs