Kaydet (Commit) 331e3459 authored tarafından Batuhan Taşkaya's avatar Batuhan Taşkaya

Implement PEP570

üst 1f357418
......@@ -240,8 +240,15 @@ class SourceGenerator(ExplicitNodeVisitor):
self.write(write_comma, arg)
self.conditional_write('=', default)
loop_args(node.args, node.defaults)
self.conditional_write(write_comma, '*', node.vararg)
posonlyargs = getattr(node, "posonlyargs", [])
offset = 0
if posonlyargs:
offset += len(node.defaults) - len(node.args)
loop_args(posonlyargs, node.defaults[:offset])
self.write(write_comma, "/")
loop_args(node.args, node.defaults[offset:])
self.conditional_write(write_comma, "*", node.vararg)
kwonlyargs = self.get_kwonlyargs(node)
if kwonlyargs:
......
......@@ -27,6 +27,12 @@ New features
.. _`Issue 138`: https://github.com/berkerpeksag/astor/issues/138
.. _`PR 139`: https://github.com/berkerpeksag/astor/pull/139
* Support Python3.8's positional only arguments.
(Reported and fixed by Batuhan Taskaya in `Issue 142`_ and `PR 143`_.)
.. _`Issue 138`: https://github.com/berkerpeksag/astor/issues/142
.. _`PR 139`: https://github.com/berkerpeksag/astor/pull/143
Bug fixes
~~~~~~~~~
......
......@@ -164,6 +164,23 @@ class CodegenTestCase(unittest.TestCase, Comparisons):
pass"""
self.assertSrcRoundtrips(source)
@unittest.skipUnless(sys.version_info >= (3, 8, 0, "alpha", 4),
"positional only arguments introduced in Python 3.8")
def test_pos_only_arguments(self):
source = """
def test(a, b, /, c, *, d, **kwargs):
pass
def test(a=3, b=4, /, c=7):
pass
def test(a, b=4, /, c=8, d=9):
pass
"""
self.assertSrcRoundtrips(source)
def test_pass_arguments_node(self):
source = canonical("""
j = [1, 2, 3]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment