Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed a test case

  • Loading branch information...
commit da63262f0ec0fb51703bb4b516e70e7444c615b6 1 parent d90f050
@mitsuhiko authored
Showing with 8 additions and 11 deletions.
  1. +6 −9 jinja2/compiler.py
  2. +2 −2 jinja2/testsuite/filters.py
View
15 jinja2/compiler.py
@@ -127,12 +127,10 @@ def add_special(self, name):
self.undeclared.discard(name)
self.declared.add(name)
- def is_declared(self, name, local_only=False):
+ def is_declared(self, name):
"""Check if a name is declared in this or an outer scope."""
if name in self.declared_locally or name in self.declared_parameter:
return True
- if local_only:
- return False
return name in self.declared
def copy(self):
@@ -193,12 +191,12 @@ def copy(self):
rv.identifiers.__dict__.update(self.identifiers.__dict__)
return rv
- def inspect(self, nodes, hard_scope=False):
+ def inspect(self, nodes):
"""Walk the node and check for identifiers. If the scope is hard (eg:
enforce on a python level) overrides from outer scopes are tracked
differently.
"""
- visitor = FrameIdentifierVisitor(self.identifiers, hard_scope)
+ visitor = FrameIdentifierVisitor(self.identifiers)
for node in nodes:
visitor.visit(node)
@@ -275,9 +273,8 @@ def visit_Block(self, node):
class FrameIdentifierVisitor(NodeVisitor):
"""A visitor for `Frame.inspect`."""
- def __init__(self, identifiers, hard_scope):
+ def __init__(self, identifiers):
self.identifiers = identifiers
- self.hard_scope = hard_scope
def visit_Name(self, node):
"""All assignments to names go through this function."""
@@ -286,7 +283,7 @@ def visit_Name(self, node):
elif node.ctx == 'param':
self.identifiers.declared_parameter.add(node.name)
elif node.ctx == 'load' and not \
- self.identifiers.is_declared(node.name, self.hard_scope):
+ self.identifiers.is_declared(node.name):
self.identifiers.undeclared.add(node.name)
def visit_If(self, node):
@@ -658,7 +655,7 @@ def function_scoping(self, node, frame, children=None,
children = node.iter_child_nodes()
children = list(children)
func_frame = frame.inner()
- func_frame.inspect(children, hard_scope=True)
+ func_frame.inspect(children)
# variables that are undeclared (accessed before declaration) and
# declared locally *and* part of an outside scope raise a template
View
4 jinja2/testsuite/filters.py
@@ -85,8 +85,8 @@ def test_filesizeformat(self):
)
out = tmpl.render()
assert out == (
- '100 Bytes|1.0 KB|1.0 MB|1.0 GB|1000.0 GB|'
- '100 Bytes|1000 Bytes|976.6 KiB|953.7 MiB|931.3 GiB'
+ '100 Bytes|0.0 kB|0.0 MB|0.0 GB|0.0 TB|100 Bytes|'
+ '1000 Bytes|1.0 KiB|0.9 MiB|0.9 GiB'
)
def test_first(self):
Please sign in to comment.
Something went wrong with that request. Please try again.