From 0daf4d9068d3296306a55b01d3bb27eee2cea9b1 Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Wed, 4 Jul 2018 09:51:34 +0200 Subject: [PATCH] Asterisks in function definitions may be at the end of a func without a comma, fixes #44 --- parso/python/tree.py | 4 +++- test/test_param_splitting.py | 13 +++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/parso/python/tree.py b/parso/python/tree.py index 70de59e..294ddfe 100644 --- a/parso/python/tree.py +++ b/parso/python/tree.py @@ -537,7 +537,9 @@ def _create_params(parent, argslist_list): if child is None or child == ',': param_children = children[start:end] if param_children: # Could as well be comma and then end. - if param_children[0] == '*' and param_children[1] == ',' \ + if param_children[0] == '*' \ + and (len(param_children) == 1 + or param_children[1] == ',') \ or check_python2_nested_param(param_children[0]): for p in param_children: p.parent = parent diff --git a/test/test_param_splitting.py b/test/test_param_splitting.py index ab47dca..f04fea7 100644 --- a/test/test_param_splitting.py +++ b/test/test_param_splitting.py @@ -32,3 +32,16 @@ def test_split_params_with_stars(): assert_params(u'x, *args', x=None, args=None) assert_params(u'**kwargs', kwargs=None) assert_params(u'*args, **kwargs', args=None, kwargs=None) + + +def test_kw_only_no_kw(works_ge_py3): + """ + Parsing this should be working. In CPython the parser also parses this and + in a later step the AST complains. + """ + module = works_ge_py3.parse('def test(arg, *):\n pass') + if module is not None: + func = module.children[0] + open_, p1, asterisk, close = func._get_param_nodes() + assert p1.get_code('arg,') + assert asterisk.value == '*'