From: Zsolt Dollenstein Date: Tue, 17 Apr 2018 19:52:17 +0000 (+0100) Subject: Merge pull request #138 from ambv/star-expr X-Git-Url: https://git.madduck.net/etc/vim.git/commitdiff_plain/05070444741834a11d48f2cbfd0600f4c4d60e9d?hp=a764f1bb3b459ee6f2e752e3d67793b119a2144a Merge pull request #138 from ambv/star-expr Parse complex expressions in parameters after * and ** --- diff --git a/README.md b/README.md index e65d9810..fc1db130 100644 --- a/README.md +++ b/README.md @@ -496,6 +496,9 @@ More details can be found in [CONTRIBUTING](CONTRIBUTING.md). * generalized star expression handling, including double stars; this fixes multiplication making expressions "unsafe" for trailing commas (#132) +* fix parsing of complex expressions after star and double stars in + function parameters (#2) + ### 18.4a2 * fixed parsing of unaligned standalone comments (#99, #112) diff --git a/black.py b/black.py index c3610c74..0323f67c 100644 --- a/black.py +++ b/black.py @@ -1364,7 +1364,7 @@ def whitespace(leaf: Leaf) -> str: # noqa C901 if not prevp or prevp.type == token.LPAR: return NO - elif prev.type == token.EQUAL or prev.type == token.DOUBLESTAR: + elif prev.type in {token.EQUAL} | STARS: return NO elif p.type == syms.decorator: @@ -2165,7 +2165,7 @@ def is_python36(node: Node) -> bool: and n.children[-1].type == token.COMMA ): for ch in n.children: - if ch.type == token.STAR or ch.type == token.DOUBLESTAR: + if ch.type in STARS: return True return False diff --git a/blib2to3/Grammar.txt b/blib2to3/Grammar.txt index 4905c91e..c9cb3a7e 100644 --- a/blib2to3/Grammar.txt +++ b/blib2to3/Grammar.txt @@ -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] diff --git a/blib2to3/Grammar3.6.5.final.0.pickle b/blib2to3/Grammar3.6.5.final.0.pickle index 3a8d93d0..e9d5fabf 100644 Binary files a/blib2to3/Grammar3.6.5.final.0.pickle and b/blib2to3/Grammar3.6.5.final.0.pickle differ diff --git a/tests/expression.diff b/tests/expression.diff index bc34c0ed..dd9459c4 100644 --- a/tests/expression.diff +++ b/tests/expression.diff @@ -117,7 +117,7 @@ ] slice[0] slice[0:1] -@@ -121,85 +135,119 @@ +@@ -121,88 +135,122 @@ numpy[-(c + 1):, d] numpy[:, l[-2]] numpy[:, ::-1] @@ -184,6 +184,12 @@ async def f(): await some.complicated[0].call(with_args=(True or (1 is not 1))) +-print(* [] or [1]) ++ ++ ++print(*[] or [1]) + print(**{1: 3} if False else {x: x for x in range(3)}) +-print(* lambda x: x) -for x, in (1,), (2,), (3,): ... -for y in (): ... -for z in (i for i in (1, 2, 3)): ... @@ -226,8 +232,7 @@ - aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa -): - return True -+ -+ ++print(*lambda x: x) +for (x,) in (1,), (2,), (3,): + ... +for y in (): diff --git a/tests/expression.py b/tests/expression.py index 9c071771..2ecf5223 100644 --- a/tests/expression.py +++ b/tests/expression.py @@ -158,6 +158,9 @@ def gen(): async def f(): await some.complicated[0].call(with_args=(True or (1 is not 1))) +print(* [] or [1]) +print(**{1: 3} if False else {x: x for x in range(3)}) +print(* lambda x: x) for x, in (1,), (2,), (3,): ... for y in (): ... for z in (i for i in (1, 2, 3)): ... @@ -402,6 +405,9 @@ async def f(): await some.complicated[0].call(with_args=(True or (1 is not 1))) +print(*[] or [1]) +print(**{1: 3} if False else {x: x for x in range(3)}) +print(*lambda x: x) for (x,) in (1,), (2,), (3,): ... for y in ():