FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

bpo-33348: parse expressions after * and ** in lib2to3 by zsol · Pull Request #6586 · python/cpython · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (4) .rst  (1) .txt  (1) All 3 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
4 changes: 2 additions & 2 deletions Lib/lib2to3/Grammar.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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' or_test [comp_iter]
Expand Down
4 changes: 1 addition & 3 deletions Lib/lib2to3/fixes/fix_apply.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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 = ('imp', 'reload')
new = ImportAndCall(node, results, names)
Expand Down
7 changes: 7 additions & 0 deletions Lib/lib2to3/tests/test_parser.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
lib2to3 now recognizes expressions after ``*`` and `**` like in ``f(*[] or
[])``.

Back | FazBrowse Home | New Git URL