fixed bug with parameter parsing
authorArmin Ronacher <armin.ronacher@active-4.com>
Thu, 15 May 2008 14:22:07 +0000 (16:22 +0200)
committerArmin Ronacher <armin.ronacher@active-4.com>
Thu, 15 May 2008 14:22:07 +0000 (16:22 +0200)
--HG--
branch : trunk

jinja2/compiler.py
jinja2/parser.py
jinja2/runtime.py

index 7a2ea4c7ea8a05b6ac163c66413770b9a06cc6d0..30054e73bd0f2ab4ddec01b2f1e29dd39a495015 100644 (file)
@@ -254,8 +254,10 @@ class FrameIdentifierVisitor(NodeVisitor):
 
     def visit_Name(self, node):
         """All assignments to names go through this function."""
-        if node.ctx in ('store', 'param'):
+        if node.ctx == 'store':
             self.identifiers.declared_locally.add(node.name)
+        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.undeclared.add(node.name)
@@ -271,8 +273,7 @@ class FrameIdentifierVisitor(NodeVisitor):
         if isinstance(node.arg, nodes.Const) and \
            isinstance(node.arg.value, basestring) and \
            ((isinstance(node.node, nodes.Name) and
-            node.node.name not in (self.identifiers.declared_locally |
-                                   self.identifiers.declared_parameter)) or \
+            node.node.name not in (self.identifiers.declared_locally)) or
             node.node in self.identifiers.static_subscribes):
             if node in self.identifiers.static_subscribes:
                 self.identifiers.static_subscribes[node] += 1
index f2a129c0abdcc00d0dc43c0f3b3fd8b7f761ca60..19ee166ec3da061bc103174205234979ba39a6ba 100644 (file)
@@ -220,6 +220,7 @@ class Parser(object):
             if args:
                 self.stream.expect('comma')
             arg = self.parse_assign_target(name_only=True)
+            arg.set_ctx('param')
             if self.stream.skip_if('assign'):
                 defaults.append(self.parse_expression())
             args.append(arg)
index cbe7115bf9a48465caf3c014b388755b6ecebfa9..b5f0783e8246499ff26adf71e0c1adc6a46fa72a 100644 (file)
@@ -121,8 +121,7 @@ class Context(object):
         return dict(self.parent, **self.vars)
 
     def _all(meth):
-        def proxy(self):
-            return getattr(self.get_all(), meth)()
+        proxy = lambda self: getattr(self.get_all(), meth)()
         proxy.__doc__ = getattr(dict, meth).__doc__
         proxy.__name__ = meth
         return proxy