- Repair some calls within the ast module that no longer work on Python3.5;
additionally replace the use of ``inspect.getargspec()`` under
Python 3 (seems to be called from the TG plugin) to avoid deprecation
warnings.
fixes #250
diff --git a/doc/build/changelog.rst b/doc/build/changelog.rst
index 5f64f0c..f733882 100644
--- a/doc/build/changelog.rst
+++ b/doc/build/changelog.rst
@@ -9,6 +9,15 @@
:version: 1.0.2
.. change::
+ :tags: bug, py3k
+ :tickets: 250
+
+ Repair some calls within the ast module that no longer work on Python3.5;
+ additionally replace the use of ``inspect.getargspec()`` under
+ Python 3 (seems to be called from the TG plugin) to avoid deprecation
+ warnings.
+
+ .. change::
:tags: bug
:pullreq: bitbucket:18
diff --git a/mako/_ast_util.py b/mako/_ast_util.py
index 604b090..cc298d5 100644
--- a/mako/_ast_util.py
+++ b/mako/_ast_util.py
@@ -486,11 +486,11 @@
paren_or_comma()
self.write(keyword.arg + '=')
self.visit(keyword.value)
- if node.starargs is not None:
+ if getattr(node, "starargs", None):
paren_or_comma()
self.write('*')
self.visit(node.starargs)
- if node.kwargs is not None:
+ if getattr(node, "kwargs", None):
paren_or_comma()
self.write('**')
self.visit(node.kwargs)
@@ -652,11 +652,11 @@
write_comma()
self.write(keyword.arg + '=')
self.visit(keyword.value)
- if node.starargs is not None:
+ if getattr(node, "starargs", None):
write_comma()
self.write('*')
self.visit(node.starargs)
- if node.kwargs is not None:
+ if getattr(node, "kwargs", None):
write_comma()
self.write('**')
self.visit(node.kwargs)
diff --git a/mako/compat.py b/mako/compat.py
index c00b100..db22b99 100644
--- a/mako/compat.py
+++ b/mako/compat.py
@@ -10,6 +10,27 @@
pypy = hasattr(sys, 'pypy_version_info')
if py3k:
+ # create a "getargspec" from getfullargspec(), which is not deprecated
+ # in Py3K; getargspec() has started to emit warnings as of Py3.5.
+ # As of Py3.4, now they are trying to move from getfullargspec()
+ # to "signature()", but getfullargspec() is not deprecated, so stick
+ # with that for now.
+
+ import collections
+ ArgSpec = collections.namedtuple(
+ "ArgSpec",
+ ["args", "varargs", "keywords", "defaults"])
+ from inspect import getfullargspec as inspect_getfullargspec
+
+ def inspect_getargspec(func):
+ return ArgSpec(
+ *inspect_getfullargspec(func)[0:4]
+ )
+else:
+ from inspect import getargspec as inspect_getargspec # noqa
+
+
+if py3k:
from io import StringIO
import builtins as compat_builtins
from urllib.parse import quote_plus, unquote_plus
diff --git a/mako/ext/turbogears.py b/mako/ext/turbogears.py
index 1a9f656..2e7d039 100644
--- a/mako/ext/turbogears.py
+++ b/mako/ext/turbogears.py
@@ -4,7 +4,6 @@
# This module is part of Mako and is released under
# the MIT License: http://www.opensource.org/licenses/mit-license.php
-import inspect
from mako import compat
from mako.lookup import TemplateLookup
from mako.template import Template
@@ -32,7 +31,7 @@
self.tmpl_options = {}
# transfer lookup args to template args, based on those available
# in getargspec
- for kw in inspect.getargspec(Template.__init__)[0]:
+ for kw in compat.inspect_getargspec(Template.__init__)[0]:
if kw in lookup_options:
self.tmpl_options[kw] = lookup_options[kw]