Skip to content

[3.7] bpo-33348: parse expressions after * and ** in lib2to3 (GH-6586) #16914

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

Merged
merged 1 commit into from
Oct 24, 2019
Merged
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
4 changes: 1 addition & 3 deletions Lib/lib2to3/fixes/fix_apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,8 @@ def transform(self, node, results):
# I feel like we should be able to express this logic in the
# PATTERN above but I don't know how to do it so...
if args:
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
4 changes: 1 addition & 3 deletions Lib/lib2to3/fixes/fix_intern.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,8 @@ def transform(self, node, results):
# PATTERN above but I don't know how to do it so...
obj = results['obj']
if obj:
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
4 changes: 1 addition & 3 deletions Lib/lib2to3/fixes/fix_reload.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,8 @@ def transform(self, node, results):
# PATTERN above but I don't know how to do it so...
obj = results['obj']
if obj:
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
7 changes: 7 additions & 0 deletions Lib/lib2to3/tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,13 @@ def test_double_star_dict_literal(self):
def test_double_star_dict_literal_after_keywords(self):
self.validate("""func(spam='fried', **{'eggs':'scrambled'})""")

def test_double_star_expression(self):
self.validate("""func(**{'a':2} or {})""")
self.validate("""func(**() or {})""")

def test_star_expression(self):
self.validate("""func(*[] or [2])""")

def test_list_display(self):
self.validate("""[*{2}, 3, *[4]]""")

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
lib2to3 now recognizes expressions after ``*`` and `**` like in ``f(*[] or
[])``.