]> git.madduck.net Git - etc/vim.git/commitdiff

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

Allow `for`'s target expression to be starred (#2879)
authorBatuhan Taskaya <isidentical@gmail.com>
Sat, 5 Mar 2022 01:37:16 +0000 (04:37 +0300)
committerGitHub <noreply@github.com>
Sat, 5 Mar 2022 01:37:16 +0000 (17:37 -0800)
Fixes #2878

CHANGES.md
src/blib2to3/Grammar.txt
tests/data/starred_for_target.py [new file with mode: 0644]
tests/test_format.py

index a0b87c780150fc537e7cd1a63cd644644d4cf30f..ac9212e994028e394162a8de5f08f2bc7659a7f8 100644 (file)
@@ -50,7 +50,8 @@
 
 ### Parser
 
-<!-- Changes to the parser or to version autodetection -->
+- Black can now parse starred expressions in the target of `for` and `async for`
+  statements, e.g `for item in *items_1, *items_2: pass` (#2879).
 
 ### Performance
 
index cf4799f8abe860acff10cb1c0fe84ec5130a3b77..0ce6cf39111566aecb7a6a9d6d0d86d08f5132e1 100644 (file)
@@ -109,7 +109,7 @@ compound_stmt: if_stmt | while_stmt | for_stmt | try_stmt | with_stmt | funcdef
 async_stmt: ASYNC (funcdef | with_stmt | for_stmt)
 if_stmt: 'if' namedexpr_test ':' suite ('elif' namedexpr_test ':' suite)* ['else' ':' suite]
 while_stmt: 'while' namedexpr_test ':' suite ['else' ':' suite]
-for_stmt: 'for' exprlist 'in' testlist ':' suite ['else' ':' suite]
+for_stmt: 'for' exprlist 'in' testlist_star_expr ':' suite ['else' ':' suite]
 try_stmt: ('try' ':' suite
            ((except_clause ':' suite)+
            ['else' ':' suite]
diff --git a/tests/data/starred_for_target.py b/tests/data/starred_for_target.py
new file mode 100644 (file)
index 0000000..8fc8e05
--- /dev/null
@@ -0,0 +1,27 @@
+for x in *a, *b:
+    print(x)
+
+for x in a, b, *c:
+    print(x)
+
+for x in *a, b, c:
+    print(x)
+
+for x in *a, b, *c:
+    print(x)
+
+async for x in *a, *b:
+    print(x)
+
+async for x in *a, b, *c:
+    print(x)
+
+async for x in a, b, *c:
+    print(x)
+
+async for x in (
+    *loooooooooooooooooooooong,
+    very,
+    *loooooooooooooooooooooooooooooooooooooooooooooooong,
+):
+    print(x)
index 04676c1c2c52a578a94a20845e1089149a4857ca..04eda43d5cfd0435fa79a0dedd677746747e94e2 100644 (file)
@@ -62,6 +62,7 @@ SIMPLE_CASES: List[str] = [
 ]
 
 PY310_CASES: List[str] = [
+    "starred_for_target",
     "pattern_matching_simple",
     "pattern_matching_complex",
     "pattern_matching_extras",