| Server IP : 217.160.0.135 / Your IP : 216.73.216.115 Web Server : Apache System : Linux www 6.18.52-i1-ampere #1203 SMP Mon Sep 14 18:29:59 CEST 2026 aarch64 User : sws1074145052 ( 1074145052) PHP Version : 8.3.32 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /usr/lib/python3/dist-packages/pythran/analyses/ |
Upload File : |
"""
OptimizableComp finds whether a comprehension can be optimized.
"""
from pythran.analyses.identifiers import Identifiers
from pythran.passmanager import NodeAnalysis
class OptimizableComprehension(NodeAnalysis):
"""Find whether a comprehension can be optimized."""
def __init__(self):
self.result = set()
super(OptimizableComprehension, self).__init__(Identifiers)
def check_comprehension(self, iters):
targets = {gen.target.id for gen in iters}
optimizable = True
for it in iters:
ids = self.gather(Identifiers, it)
optimizable &= all(((ident == it.target.id) |
(ident not in targets)) for ident in ids)
return optimizable
def visit_ListComp(self, node):
if (self.check_comprehension(node.generators)):
self.result.add(node)
def visit_GeneratorExp(self, node):
if (self.check_comprehension(node.generators)):
self.result.add(node)