Fix placement of dictionary unpacking inside dict literals

Fixes #111
This commit is contained in:
Łukasz Langa 2018-04-11 23:19:03 -07:00
parent e41844feb7
commit 19d69b34e5
4 changed files with 24 additions and 2 deletions

View File

@ -495,6 +495,8 @@ More details can be found in [CONTRIBUTING](CONTRIBUTING.md).
* fixed parsing of unaligned standalone comments (#99, #112)
* fixed placement of dictionary unpacking inside dictionary literals (#111)
### 18.4a1
* added `--quiet` (#78)

View File

@ -1498,7 +1498,7 @@ def is_split_before_delimiter(leaf: Leaf, previous: Leaf = None) -> int:
if (
leaf.type in VARARGS
and leaf.parent
and leaf.parent.type in {syms.argument, syms.typedargslist}
and leaf.parent.type in {syms.argument, syms.typedargslist, syms.dictsetmaker}
):
# * and ** might also be MATH_OPERATORS but in this case they are not.
# Don't treat them as a delimiter.

View File

@ -103,7 +103,7 @@
]
slice[0]
slice[0:1]
@@ -114,78 +123,104 @@
@@ -114,79 +123,113 @@
numpy[-(c + 1):, d]
numpy[:, l[-2]]
numpy[:, ::-1]
@ -123,6 +123,16 @@
+((i ** 2) for i, _ in ((1, "a"), (2, "b"), (3, "c")))
(((i ** 2) + j) for i in (1, 2, 3) for j in (1, 2, 3))
(*starred)
-{"id": "1","type": "type","started_at": now(),"ended_at": now() + timedelta(days=10),"priority": 1,"import_session_id": 1,**kwargs} # no trailing comma, this file is not 3.6+
+{
+ "id": "1",
+ "type": "type",
+ "started_at": now(),
+ "ended_at": now() + timedelta(days=10),
+ "priority": 1,
+ "import_session_id": 1,
+ **kwargs
+} # no trailing comma, this file is not 3.6+
a = (1,)
b = 1,
c = 1

View File

@ -127,6 +127,7 @@
((i ** 2) for i, _ in ((1, 'a'), (2, 'b'), (3, 'c')))
(((i ** 2) + j) for i in (1, 2, 3) for j in (1, 2, 3))
(*starred)
{"id": "1","type": "type","started_at": now(),"ended_at": now() + timedelta(days=10),"priority": 1,"import_session_id": 1,**kwargs} # no trailing comma, this file is not 3.6+
a = (1,)
b = 1,
c = 1
@ -331,6 +332,15 @@ async def f():
((i ** 2) for i, _ in ((1, "a"), (2, "b"), (3, "c")))
(((i ** 2) + j) for i in (1, 2, 3) for j in (1, 2, 3))
(*starred)
{
"id": "1",
"type": "type",
"started_at": now(),
"ended_at": now() + timedelta(days=10),
"priority": 1,
"import_session_id": 1,
**kwargs
} # no trailing comma, this file is not 3.6+
a = (1,)
b = 1,
c = 1