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

bpo-36541: lib2to3: Support complex expressions in *args and **kwargs. by thatch · Pull Request #12703 · python/cpython · GitHub

Repository navigation

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

Filter by extension

Filter by extension .py  (4) .txt  (1) All 2 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' testlist_safe [comp_iter]
Expand Down
2 changes: 1 addition & 1 deletion 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 @@ -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
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 @@ -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
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,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
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 @@ -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

Back | FazBrowse Home | New Git URL