Skip to content
This repository was archived by the owner on Jul 11, 2022. It is now read-only.

Commit 0507044

Browse files
authored
Merge pull request pytest-dev#138 from ambv/star-expr
Parse complex expressions in parameters after * and **
2 parents a764f1b + 68cc978 commit 0507044

File tree

6 files changed

+21
-7
lines changed

6 files changed

+21
-7
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,9 @@ More details can be found in [CONTRIBUTING](CONTRIBUTING.md).
496496
* generalized star expression handling, including double stars; this
497497
fixes multiplication making expressions "unsafe" for trailing commas (#132)
498498

499+
* fix parsing of complex expressions after star and double stars in
500+
function parameters (#2)
501+
499502
### 18.4a2
500503

501504
* fixed parsing of unaligned standalone comments (#99, #112)

black.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1364,7 +1364,7 @@ def whitespace(leaf: Leaf) -> str: # noqa C901
13641364
if not prevp or prevp.type == token.LPAR:
13651365
return NO
13661366

1367-
elif prev.type == token.EQUAL or prev.type == token.DOUBLESTAR:
1367+
elif prev.type in {token.EQUAL} | STARS:
13681368
return NO
13691369

13701370
elif p.type == syms.decorator:
@@ -2165,7 +2165,7 @@ def is_python36(node: Node) -> bool:
21652165
and n.children[-1].type == token.COMMA
21662166
):
21672167
for ch in n.children:
2168-
if ch.type == token.STAR or ch.type == token.DOUBLESTAR:
2168+
if ch.type in STARS:
21692169
return True
21702170

21712171
return False

blib2to3/Grammar.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,8 @@ arglist: argument (',' argument)* [',']
138138
# that precede iterable unpackings are blocked; etc.
139139
argument: ( test [comp_for] |
140140
test '=' test |
141-
'**' expr |
142-
star_expr )
141+
'**' test |
142+
'*' test )
143143

144144
comp_iter: comp_for | comp_if
145145
comp_for: [ASYNC] 'for' exprlist 'in' or_test [comp_iter]

blib2to3/Grammar3.6.5.final.0.pickle

-9 Bytes
Binary file not shown.

tests/expression.diff

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@
117117
]
118118
slice[0]
119119
slice[0:1]
120-
@@ -121,85 +135,119 @@
120+
@@ -121,88 +135,122 @@
121121
numpy[-(c + 1):, d]
122122
numpy[:, l[-2]]
123123
numpy[:, ::-1]
@@ -184,6 +184,12 @@
184184

185185
async def f():
186186
await some.complicated[0].call(with_args=(True or (1 is not 1)))
187+
-print(* [] or [1])
188+
+
189+
+
190+
+print(*[] or [1])
191+
print(**{1: 3} if False else {x: x for x in range(3)})
192+
-print(* lambda x: x)
187193
-for x, in (1,), (2,), (3,): ...
188194
-for y in (): ...
189195
-for z in (i for i in (1, 2, 3)): ...
@@ -226,8 +232,7 @@
226232
- aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
227233
-):
228234
- return True
229-
+
230-
+
235+
+print(*lambda x: x)
231236
+for (x,) in (1,), (2,), (3,):
232237
+ ...
233238
+for y in ():

tests/expression.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,9 @@ def gen():
158158

159159
async def f():
160160
await some.complicated[0].call(with_args=(True or (1 is not 1)))
161+
print(* [] or [1])
162+
print(**{1: 3} if False else {x: x for x in range(3)})
163+
print(* lambda x: x)
161164
for x, in (1,), (2,), (3,): ...
162165
for y in (): ...
163166
for z in (i for i in (1, 2, 3)): ...
@@ -402,6 +405,9 @@ async def f():
402405
await some.complicated[0].call(with_args=(True or (1 is not 1)))
403406

404407

408+
print(*[] or [1])
409+
print(**{1: 3} if False else {x: x for x in range(3)})
410+
print(*lambda x: x)
405411
for (x,) in (1,), (2,), (3,):
406412
...
407413
for y in ():

0 commit comments

Comments
 (0)