Skip to content

Commit

Permalink
Merge pull request #2 from fjarri/py35-support
Browse files Browse the repository at this point in the history
Support for Python 3.5
  • Loading branch information
simonpercivall committed Jan 17, 2016
2 parents de80659 + 9843043 commit ed7e374
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 28 deletions.
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Basic example::
astunparse.dump(ast.parse(inspect.getsource(ast)))


This library is single-source compatible with Python 2.6 through Python 3.4. It
This library is single-source compatible with Python 2.6 through Python 3.5. It
is authored by the Python core developers; I have simply merged the Python 2.7
and the Python 3.4 source and test suites, and added a wrapper. This factoring
out is to provide a library implementation that supports both versions.
Expand Down
71 changes: 46 additions & 25 deletions lib/astunparse/unparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,16 +286,17 @@ def _ClassDef(self, t):
if comma: self.write(", ")
else: comma = True
self.dispatch(e)
if t.starargs:
if comma: self.write(", ")
else: comma = True
self.write("*")
self.dispatch(t.starargs)
if t.kwargs:
if comma: self.write(", ")
else: comma = True
self.write("**")
self.dispatch(t.kwargs)
if sys.version_info[:2] < (3, 5):
if t.starargs:
if comma: self.write(", ")
else: comma = True
self.write("*")
self.dispatch(t.starargs)
if t.kwargs:
if comma: self.write(", ")
else: comma = True
self.write("**")
self.dispatch(t.kwargs)
self.write(")")
elif t.bases:
self.write("(")
Expand All @@ -307,12 +308,12 @@ def _ClassDef(self, t):
self.dispatch(t.body)
self.leave()

def _FunctionDef(self, t):
def _generic_FunctionDef(self, t, async=False):
self.write("\n")
for deco in t.decorator_list:
self.fill("@")
self.dispatch(deco)
self.fill("def "+t.name + "(")
self.fill(("async " if async else "") + "def " + t.name + "(")
self.dispatch(t.args)
self.write(")")
if getattr(t, "returns", False):
Expand All @@ -322,6 +323,12 @@ def _FunctionDef(self, t):
self.dispatch(t.body)
self.leave()

def _FunctionDef(self, t):
self._generic_FunctionDef(t)

def _AsyncFunctionDef(self, t):
self._generic_FunctionDef(t, async=True)

def _For(self, t):
self.fill("for ")
self.dispatch(t.target)
Expand Down Expand Up @@ -528,7 +535,8 @@ def _UnaryOp(self, t):

binop = { "Add":"+", "Sub":"-", "Mult":"*", "Div":"/", "Mod":"%",
"LShift":"<<", "RShift":">>", "BitOr":"|", "BitXor":"^", "BitAnd":"&",
"FloorDiv":"//", "Pow": "**"}
"FloorDiv":"//", "Pow": "**",
"MatMult":"@"}
def _BinOp(self, t):
self.write("(")
self.dispatch(t.left)
Expand Down Expand Up @@ -575,16 +583,17 @@ def _Call(self, t):
if comma: self.write(", ")
else: comma = True
self.dispatch(e)
if t.starargs:
if comma: self.write(", ")
else: comma = True
self.write("*")
self.dispatch(t.starargs)
if t.kwargs:
if comma: self.write(", ")
else: comma = True
self.write("**")
self.dispatch(t.kwargs)
if sys.version_info[:2] < (3, 5):
if t.starargs:
if comma: self.write(", ")
else: comma = True
self.write("*")
self.dispatch(t.starargs)
if t.kwargs:
if comma: self.write(", ")
else: comma = True
self.write("**")
self.dispatch(t.kwargs)
self.write(")")

def _Subscript(self, t):
Expand Down Expand Up @@ -680,8 +689,12 @@ def _arguments(self, t):
self.dispatch(t.kwargannotation)

def _keyword(self, t):
self.write(t.arg)
self.write("=")
if t.arg is None:
# starting from Python 3.5 this denotes a kwargs part of the invocation
self.write("**")
else:
self.write(t.arg)
self.write("=")
self.dispatch(t.value)

def _Lambda(self, t):
Expand All @@ -703,6 +716,14 @@ def _withitem(self, t):
self.write(" as ")
self.dispatch(t.optional_vars)

def _Await(self, t):
self.write("(")
self.write("await")
if t.value:
self.write(" ")
self.dispatch(t.value)
self.write(")")

def roundtrip(filename, output=sys.stdout):
if six.PY3:
with open(filename, "rb") as pyfile:
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def read_version():
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Topic :: Software Development :: Code Generators',
],
test_suite='tests',
Expand Down
4 changes: 2 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tox]
envlist = py26, py27, py32, py33, py34
envlist = py26, py27, py32, py33, py34, py35

[testenv]
usedevelop = True
Expand Down Expand Up @@ -43,7 +43,7 @@ deps =
-rtest_requirements.txt

[testenv:ipython3]
basepython = python3.4
basepython = python3.5
usedevelop = True
commands = ipython3
deps =
Expand Down

0 comments on commit ed7e374

Please sign in to comment.