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

Commit

Permalink
Fix placement of dictionary unpacking inside dict literals
Browse files Browse the repository at this point in the history
  • Loading branch information
ambv committed Apr 12, 2018
1 parent e41844f commit 19d69b3
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 deletions.
2 changes: 2 additions & 0 deletions README.md
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion black.py
Expand Up @@ -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.
Expand Down
12 changes: 11 additions & 1 deletion tests/expression.diff
Expand Up @@ -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]
Expand All @@ -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
Expand Down
10 changes: 10 additions & 0 deletions tests/expression.py
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 19d69b3

Please sign in to comment.