From 853edc878adb623509f6cc18bf870e7cdb433c25 Mon Sep 17 00:00:00 2001 From: Yilei Yang Date: Fri, 16 Jun 2023 09:23:20 -0700 Subject: [PATCH] Cherry pick https://github.com/psf/black/pull/3735. Why not rebase? Black has unreleased changes in blib2to3, rebasing will make Pyink releases harder. Will wait for a new Black release before we rebase. PiperOrigin-RevId: 540903043 --- patches/pyink.patch | 16 +++++++++++++++- src/pyink/linegen.py | 7 +++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/patches/pyink.patch b/patches/pyink.patch index a951dc6ae01..e987dd74cf4 100644 --- a/patches/pyink.patch +++ b/patches/pyink.patch @@ -681,7 +681,21 @@ if leaves: # Since body is a new indent level, remove spurious leading whitespace. normalize_prefix(leaves[0], inside_brackets=True) -@@ -1449,7 +1551,7 @@ def generate_trailers_to_omit(line: Line +@@ -915,6 +1017,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: +@@ -1449,7 +1558,7 @@ def generate_trailers_to_omit(line: Line if not line.magic_trailing_comma: yield omit diff --git a/src/pyink/linegen.py b/src/pyink/linegen.py index 76a2e4f78e2..b9a998d33ea 100644 --- a/src/pyink/linegen.py +++ b/src/pyink/linegen.py @@ -1008,6 +1008,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: