U ar@s`dZddlZddlmZddlmZejr6ddlm Z ej dej dd d Z Gd d d eZ dS) 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. N)nodes)NodeTransformer) Environmentr)node environmentreturncCst|}ttj||S)z^The context hint can be used to perform an static optimization based on the context given.) OptimizertcastrNodevisit)rrZ optimizerrQC:\Users\vtejo\AppData\Local\Temp\pip-unpacked-wheel-8gbwd15f\jinja2\optimizer.pyoptimizesrcs@eZdZdddddZejejejejdfdd ZZ S) r zt.Optional[Environment]N)rrcCs ||_dS)N)r)selfrrrr__init__szOptimizer.__init__)rargskwargsrcsftj|f||}t|tjrbz*tjj||r8|dnd|j|j dWStj k r`YnX|S)Nr)linenor) super generic_visit isinstancerZExprZConstZfrom_untrustedZas_constrrZ Impossible)rrrr __class__rrrs zOptimizer.generic_visit) __name__ __module__ __qualname__rrr r Anyr __classcell__rrrrr s r ) __doc__typingr rZvisitorr TYPE_CHECKINGrrr rr rrrrs