From: Jelle Zijlstra Date: Sat, 23 Feb 2019 06:00:40 +0000 (-0800) Subject: split long del statements into multiple lines (#698) X-Git-Url: https://git.madduck.net/etc/vim.git/commitdiff_plain/f5b14b1afd1ceb240c0b46a2cd3e380a4da857df?ds=inline split long del statements into multiple lines (#698) Fixes #693 --- diff --git a/README.md b/README.md index b25f64f..57272ae 100644 --- a/README.md +++ b/README.md @@ -944,10 +944,12 @@ More details can be found in [CONTRIBUTING](CONTRIBUTING.md). ### 19.2b0 -* *Black* no longer normalizes numeric literals to include `_` separators. +* long `del` statements are now split into multiple lines (#698) + +* *Black* no longer normalizes numeric literals to include `_` separators (#696) * new option `--target-version` to control which Python versions - *Black*-formatted code should target + *Black*-formatted code should target (#618) ### 18.9b0 diff --git a/black.py b/black.py index 34bd59e..8f50d3e 100644 --- a/black.py +++ b/black.py @@ -1646,6 +1646,7 @@ class LineGenerator(Visitor[Line]): self.visit_expr_stmt = partial(v, keywords=Ø, parens=ASSIGNMENTS) self.visit_return_stmt = partial(v, keywords={"return"}, parens={"return"}) self.visit_import_from = partial(v, keywords=Ø, parens={"import"}) + self.visit_del_stmt = partial(v, keywords=Ø, parens={"del"}) self.visit_async_funcdef = self.visit_async_stmt self.visit_decorated = self.visit_decorators @@ -3350,7 +3351,16 @@ def assert_equivalent(src: str, dst: str) -> None: if isinstance(value, list): for item in value: - if isinstance(item, ast.AST): + # Ignore nested tuples within del statements, because we may insert + # parentheses and they change the AST. + if ( + field == "targets" + and isinstance(node, ast.Delete) + and isinstance(item, ast.Tuple) + ): + for item in item.elts: + yield from _v(item, depth + 2) + elif isinstance(item, ast.AST): yield from _v(item, depth + 2) elif isinstance(value, ast.AST): diff --git a/tests/data/cantfit.py b/tests/data/cantfit.py index 2a7cde3..0ab1575 100644 --- a/tests/data/cantfit.py +++ b/tests/data/cantfit.py @@ -36,6 +36,7 @@ for key in """ if key in self.connect_kwargs: raise ValueError(err.format(key)) concatenated_strings = "some strings that are" "concatenated implicitly, so if you put them on separate" "lines it will fit" +del concatenated_strings, string_variable_name, normal_function_name, normal_name, need_more_to_make_the_line_long_enough # output @@ -91,3 +92,10 @@ concatenated_strings = ( "concatenated implicitly, so if you put them on separate" "lines it will fit" ) +del ( + concatenated_strings, + string_variable_name, + normal_function_name, + normal_name, + need_more_to_make_the_line_long_enough, +)