Skip to content
Myr

removed loop.parent. If this variable is wanted you can get it by doing something like `{% parent_looo = loop %}` before the iteration

Before adoption: this commit came in with the history the project adopted, so no landing records it.

--HG-- branch : trunk

authored by Armin Ronacher · committed by Armin Ronacher · parent 4c81b16 · Browse files · 3 files+6 added−15 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+6 added−15 removed

  • other:+6 added−15 removed

3 files+6 added−15 removed

modified:jinja2/compiler.py-2 removed
654 unmodified lines
655656 else:657 self.visit(node.iter, loop_frame)658659 if 'loop' in aliases:660 self.write(', ' + aliases['loop'])659 self.write(extended_loop and '):' or ':')660661 # tests in not extended loops become a continue662 if not extended_loop and node.test is not None:
388 unmodified lines
modified:jinja2/optimizer.py+1 added-2 removed
143 unmodified lines
144 raise TypeError()145 except (nodes.Impossible, TypeError):146 return fallback147148 parent = context.get('loop')148 context.push()149 result = []150 iterated = False151
27 unmodified lines
179 iterable = filtered_sequence180181 try:182 try:184 for item, loop in LoopContext(iterable, parent, True):183 for item, loop in LoopContext(iterable, True):184 context['loop'] = loop.make_static()185 assign(node.target, item)186 result.extend(self.visit(n.copy(), context)187 for n in node.body)
79 unmodified lines
modified:jinja2/runtime.py+5 added-11 removed
150 unmodified lines
151152class LoopContext(LoopContextBase):153 """A loop context for dynamic iteration."""154155 def __init__(self, iterable, parent=None, enforce_length=False):155 def __init__(self, iterable, enforce_length=False):156 self._iterable = iterable157 self._next = iter(iterable).next158 self._length = None159 self.index0 = -1160 self.parent = parent160 if enforce_length:161 len(self)162163 def make_static(self):164 """Return a static loop context for the optimizer."""166 parent = None167 if self.parent is not None:168 parent = self.parent.make_static()169 return StaticLoopContext(self.index0, self.length, parent)165 return StaticLoopContext(self.index0, self.length)166167 def __iter__(self):168 return self169
22 unmodified lines
192 status of an iteration. The only reason for this object is if the193 loop object is accessed in a non static way (eg: becomes part of a194 function call)."""195200 def __init__(self, index0, length, parent):196 def __init__(self, index0, length):197 self.index0 = index0202 self.parent = parent198 self.length = length199200 def __repr__(self):201 """The repr is used by the optimizer to dump the object."""207 return 'StaticLoopContext(%r, %r, %r)' % (202 return 'StaticLoopContext(%r, %r)' % (203 self.index0,209 self.length,210 self.parent204 self.length205 )206207 def make_static(self):208 return self
123 unmodified lines