]> Devi Nivas Git - chevron.git/commitdiff
Stop using a leaked variable. (flake8)
authornoah morrison <noah@morrison.ph>
Sun, 25 Jan 2015 20:43:08 +0000 (15:43 -0500)
committernoah morrison <noah@morrison.ph>
Sun, 25 Jan 2015 20:43:08 +0000 (15:43 -0500)
scope is a variable that is defined lower in the for loop
and is leaked up in a future pass.

Also this code was slightly convoluted.
The goal is to stop rendering while the current scope is falsy.
Adding a new falsy scopes for every section inside
(So it doesn't start rendering on the next end tag).

I don't really know what I was thinking when I first coded this,
but all we have to do is add False instead of whatever in the
world I was doing before.

chevron/renderer.py

index a665122c696942fecf284c07aea23587af4698e8..86ab624d311b441862eb40cd822eee3305fdf47e 100644 (file)
@@ -169,15 +169,10 @@ def render(template='', data={}, partials_path='.', partials_ext='mustache',
 
         # If the current scope is falsy and not the only scope
         elif not current_scope and len(scopes) != 1:
-            # If we're a section tag
-            if tag == 'section':
-                # Set it as the most recent scope
-                scopes.insert(0, scope)
-
-            # If we're an inverted section tag
-            elif tag == 'inverted section':
-                # Set the flipped scope as the most recent scope
-                scopes.insert(0, not scope)
+            if tag in ['section', 'inverted section']:
+                # Set the most recent scope to a falsy value
+                # (I heard False is a good one)
+                scopes.insert(0, False)
 
         # If we're a literal tag
         elif tag == 'literal':