Skip to content

Commit

Permalink
Fixed a test case
Browse files Browse the repository at this point in the history
  • Loading branch information
mitsuhiko committed Mar 13, 2011
1 parent d90f050 commit da63262
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
15 changes: 6 additions & 9 deletions jinja2/compiler.py
Expand Up @@ -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):
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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."""
Expand All @@ -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):
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions jinja2/testsuite/filters.py
Expand Up @@ -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):
Expand Down

0 comments on commit da63262

Please sign in to comment.