Anonymous committed 34c7b28

added arg_stringname function to
This is to be compatible with python3.4 where kwarg and vararg
objects are _ast.arg as opposed to Name objects in earlier versions.
The _ast.arg object cannot be implicitly converted to a string. This
lead to 4 errors in the test suite.

As of this commit all tests pass under python3.4a2

  • Participants
  • Parent commits 951c174

Comments (0)

Files changed (3)

File mako/

+def arg_stringname(func_arg):
+    """Gets the string name of a kwarg or vararg
+    In Python3.4 a function's args are
+    of _ast.arg type not
+    """
+    if hasattr(func_arg, 'arg'):
+        return func_arg.arg
+    else:
+        return str(func_arg)
 def parse(expr, filename='<unknown>', mode='exec'):
     """Parse an expression into an AST node."""
         if node.vararg is not None:
-            self.write('*' + node.vararg)
+            self.write('*' + arg_stringname(node.vararg))
         if node.kwarg is not None:
-            self.write('**' + node.kwarg)
+            self.write('**' + arg_stringname(node.kwarg))
     def decorators(self, node):
         for decorator in node.decorator_list:
 code, as well as generating Python from AST nodes"""
 from mako import exceptions, pyparser, compat
+from mako._ast_util import arg_stringname
 import re
 class PythonCode(object):
         for arg in argnames:
             default = None
             if kwargs:
-                arg = "**" + arg
+                arg = "**" + arg_stringname(arg)
                 kwargs = False
             elif varargs:
-                arg = "*" + arg
+                arg = "*" + arg_stringname(arg)
                 varargs = False
                 default = len(defaults) and defaults.pop() or None

File mako/

 from mako import exceptions, util, compat
+from mako._ast_util import arg_stringname
 from mako.compat import StringIO
 import operator
             self.listener.funcname =
             argnames = [arg_id(arg) for arg in node.args.args]
             if node.args.vararg:
-                argnames.append(node.args.vararg)
+                argnames.append(arg_stringname(node.args.vararg))
             if node.args.kwarg:
-                argnames.append(node.args.kwarg)
+                argnames.append(arg_stringname(node.args.kwarg))
             self.listener.argnames = argnames
             self.listener.defaults = node.args.defaults  # ast
             self.listener.varargs = node.args.vararg
             self.listener.kwargs = node.args.kwarg
     class ExpressionGenerator(object):
         def __init__(self, astnode):