From da63262f0ec0fb51703bb4b516e70e7444c615b6 Mon Sep 17 00:00:00 2001 From: Armin Ronacher Date: Sun, 13 Mar 2011 14:33:27 -0400 Subject: [PATCH] Fixed a test case --- jinja2/compiler.py | 15 ++++++--------- jinja2/testsuite/filters.py | 4 ++-- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/jinja2/compiler.py b/jinja2/compiler.py index d0aadad..b21cb38 100644 --- a/jinja2/compiler.py +++ b/jinja2/compiler.py @@ -127,12 +127,10 @@ class Identifiers(object): 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 @@ class Frame(object): 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 @@ class UndeclaredNameVisitor(NodeVisitor): 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 @@ class FrameIdentifierVisitor(NodeVisitor): 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 @@ class CodeGenerator(NodeVisitor): 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 diff --git a/jinja2/testsuite/filters.py b/jinja2/testsuite/filters.py index ff04c9f..5bb6b12 100644 --- a/jinja2/testsuite/filters.py +++ b/jinja2/testsuite/filters.py @@ -85,8 +85,8 @@ class FilterTestCase(JinjaTestCase): ) 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): -- 2.26.2