Skip to content

bpo-36541: lib2to3: Support complex expressions in *args and **kwargs. #12703

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Lib/lib2to3/Grammar.txt
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ arglist: argument (',' argument)* [',']
# that precede iterable unpackings are blocked; etc.
argument: ( test [comp_for] |
test '=' test |
'**' expr |
star_expr )
'**' test |
'*' test )

comp_iter: comp_for | comp_if
comp_for: [ASYNC] 'for' exprlist 'in' testlist_safe [comp_iter]
Expand Down
2 changes: 1 addition & 1 deletion Lib/lib2to3/fixes/fix_apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def transform(self, node, results):
if args.type == self.syms.star_expr:
return # Make no change.
if (args.type == self.syms.argument and
args.children[0].value == '**'):
args.children[0].value in ('*', '**')):
return # Make no change.
if kwds and (kwds.type == self.syms.argument and
kwds.children[0].value == '**'):
Expand Down
2 changes: 1 addition & 1 deletion Lib/lib2to3/fixes/fix_intern.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def transform(self, node, results):
if obj.type == self.syms.star_expr:
return # Make no change.
if (obj.type == self.syms.argument and
obj.children[0].value == '**'):
obj.children[0].value in ('*', '**')):
return # Make no change.
names = ('sys', 'intern')
new = ImportAndCall(node, results, names)
Expand Down
2 changes: 1 addition & 1 deletion Lib/lib2to3/fixes/fix_reload.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def transform(self, node, results):
if obj.type == self.syms.star_expr:
return # Make no change.
if (obj.type == self.syms.argument and
obj.children[0].value == '**'):
obj.children[0].value in ('*', '**')):
return # Make no change.
names = ('importlib', 'reload')
new = ImportAndCall(node, results, names)
Expand Down
14 changes: 14 additions & 0 deletions Lib/lib2to3/tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,20 @@ def test_multiline_str_literals(self):
self.validate(s)


class TestStarArgumentsExpr(GrammarTest):

def test_arg_expressions(self):
driver.parse_string("f(*x)\n")
driver.parse_string("f(*x or [1])\n")
driver.parse_string("f(*x if x else [1])\n")

def test_kwarg_expressions(self):
driver.parse_string("f(**x)\n")
driver.parse_string("f(**not x)\n")
driver.parse_string("f(**x or {})\n")
driver.parse_string("f(**x if x else {})\n")


class TestPickleableException(unittest.TestCase):
def test_ParseError(self):
err = ParseError('msg', 2, None, (1, 'context'))
Expand Down