From: Jelle Zijlstra Date: Sun, 27 Oct 2019 11:31:10 +0000 (-0700) Subject: fix crash with long type annotations (#1093) X-Git-Url: https://git.madduck.net/etc/vim.git/commitdiff_plain/53808e390294d717d69c71044527890d4ab7452e fix crash with long type annotations (#1093) --- diff --git a/black.py b/black.py index ada9b0e..5b2e017 100644 --- a/black.py +++ b/black.py @@ -2601,9 +2601,11 @@ def bracket_split_build_line( # Since body is a new indent level, remove spurious leading whitespace. normalize_prefix(leaves[0], inside_brackets=True) # Ensure a trailing comma for imports and standalone function arguments, but - # be careful not to add one after any comments. - no_commas = original.is_def and not any( - l.type == token.COMMA for l in leaves + # be careful not to add one after any comments or within type annotations. + no_commas = ( + original.is_def + and opening_bracket.value == "(" + and not any(l.type == token.COMMA for l in leaves) ) if original.is_import or no_commas: diff --git a/tests/data/function_trailing_comma.py b/tests/data/function_trailing_comma.py index f2594c6..fcd81ad 100644 --- a/tests/data/function_trailing_comma.py +++ b/tests/data/function_trailing_comma.py @@ -4,6 +4,11 @@ def f(a,): def f(a:int=1,): ... +def xxxxxxxxxxxxxxxxxxxxxxxxxxxx() -> Set[ + "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" +]: + pass + # output def f(a,): @@ -12,3 +17,9 @@ def f(a,): def f(a: int = 1,): ... + + +def xxxxxxxxxxxxxxxxxxxxxxxxxxxx() -> Set[ + "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" +]: + pass