]> 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:

Do not add trailing commas to return type annotations using PEP 604 unions (#3735)
authorYilei "Dolee" Yang <yileiyang@google.com>
Fri, 16 Jun 2023 00:08:26 +0000 (17:08 -0700)
committerGitHub <noreply@github.com>
Fri, 16 Jun 2023 00:08:26 +0000 (17:08 -0700)
Fix #3638: Do not add trailing commas to return type annotations using PEP 604 unions.

CHANGES.md
src/black/linegen.py
tests/data/simple_cases/pep_604.py [new file with mode: 0644]

index 658faad3a78bba23fe62346f66336dd9f88b3c8f..fd4d911287dcb40abe285442bb9d2c72ad48ceca 100644 (file)
@@ -10,6 +10,9 @@
 
 <!-- Changes that affect Black's stable style -->
 
+- Fix a bug where an illegal trailing comma was added to return type annotations using
+  PEP 604 unions (#3735)
+
 ### Preview style
 
 <!-- Changes that affect Black's preview style -->
index 0091cbb3bd1d3195d3bc06fed11aeac280b987bf..ad21307c311b83b0e0eb964b34ae6149cfcb0cee 100644 (file)
@@ -918,6 +918,13 @@ def bracket_split_build_line(
                     )
                     if isinstance(node, Node) and isinstance(node.prev_sibling, Leaf)
                 )
+                # Except the false negatives above for PEP 604 unions where we
+                # can't add the comma.
+                and not (
+                    leaves[0].parent
+                    and leaves[0].parent.next_sibling
+                    and leaves[0].parent.next_sibling.type == token.VBAR
+                )
             )
 
             if original.is_import or no_commas:
diff --git a/tests/data/simple_cases/pep_604.py b/tests/data/simple_cases/pep_604.py
new file mode 100644 (file)
index 0000000..b68d59d
--- /dev/null
@@ -0,0 +1,25 @@
+def some_very_long_name_function() -> my_module.Asdf | my_module.AnotherType | my_module.YetAnotherType | None:
+    pass
+
+
+def some_very_long_name_function() -> my_module.Asdf | my_module.AnotherType | my_module.YetAnotherType | my_module.EvenMoreType | None:
+    pass
+
+
+# output
+
+
+def some_very_long_name_function() -> (
+    my_module.Asdf | my_module.AnotherType | my_module.YetAnotherType | None
+):
+    pass
+
+
+def some_very_long_name_function() -> (
+    my_module.Asdf
+    | my_module.AnotherType
+    | my_module.YetAnotherType
+    | my_module.EvenMoreType
+    | None
+):
+    pass