Skip to content

Commit

Permalink
removed loop.parent. If this variable is wanted you can get it by doi…
Browse files Browse the repository at this point in the history
…ng something like `{% parent_looo = loop %}` before the iteration

--HG--
branch : trunk
  • Loading branch information
mitsuhiko committed Apr 18, 2008
1 parent 4c81b16 commit f64efb8
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 15 deletions.
2 changes: 0 additions & 2 deletions jinja2/compiler.py
Expand Up @@ -656,8 +656,6 @@ def visit_For(self, node, frame):
else:
self.visit(node.iter, loop_frame)

if 'loop' in aliases:
self.write(', ' + aliases['loop'])
self.write(extended_loop and '):' or ':')

# tests in not extended loops become a continue
Expand Down
3 changes: 1 addition & 2 deletions jinja2/optimizer.py
Expand Up @@ -145,7 +145,6 @@ def visit_For(self, node, context):
except (nodes.Impossible, TypeError):
return fallback

parent = context.get('loop')
context.push()
result = []
iterated = False
Expand Down Expand Up @@ -181,7 +180,7 @@ def assign(target, value):

try:
try:
for item, loop in LoopContext(iterable, parent, True):
for item, loop in LoopContext(iterable, True):
context['loop'] = loop.make_static()
assign(node.target, item)
result.extend(self.visit(n.copy(), context)
Expand Down
16 changes: 5 additions & 11 deletions jinja2/runtime.py
Expand Up @@ -152,21 +152,17 @@ def __len__(self):
class LoopContext(LoopContextBase):
"""A loop context for dynamic iteration."""

def __init__(self, iterable, parent=None, enforce_length=False):
def __init__(self, iterable, enforce_length=False):
self._iterable = iterable
self._next = iter(iterable).next
self._length = None
self.index0 = -1
self.parent = parent
if enforce_length:
len(self)

def make_static(self):
"""Return a static loop context for the optimizer."""
parent = None
if self.parent is not None:
parent = self.parent.make_static()
return StaticLoopContext(self.index0, self.length, parent)
return StaticLoopContext(self.index0, self.length)

def __iter__(self):
return self
Expand Down Expand Up @@ -197,17 +193,15 @@ class StaticLoopContext(LoopContextBase):
loop object is accessed in a non static way (eg: becomes part of a
function call)."""

def __init__(self, index0, length, parent):
def __init__(self, index0, length):
self.index0 = index0
self.parent = parent
self.length = length

def __repr__(self):
"""The repr is used by the optimizer to dump the object."""
return 'StaticLoopContext(%r, %r, %r)' % (
return 'StaticLoopContext(%r, %r)' % (
self.index0,
self.length,
self.parent
self.length
)

def make_static(self):
Expand Down

0 comments on commit f64efb8

Please sign in to comment.