Skip to content

Commit

Permalink
split long del statements into multiple lines (#698)
Browse files Browse the repository at this point in the history
Fixes #693
  • Loading branch information
JelleZijlstra committed Feb 23, 2019
1 parent 2ae5ce1 commit f5b14b1
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
6 changes: 4 additions & 2 deletions README.md
Expand Up @@ -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

Expand Down
12 changes: 11 additions & 1 deletion black.py
Expand Up @@ -1646,6 +1646,7 @@ def __attrs_post_init__(self) -> None:
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

Expand Down Expand Up @@ -3350,7 +3351,16 @@ def _v(node: ast.AST, depth: int = 0) -> Iterator[str]:

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):
Expand Down
8 changes: 8 additions & 0 deletions tests/data/cantfit.py
Expand Up @@ -36,6 +36,7 @@
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
Expand Down Expand Up @@ -91,3 +92,10 @@
"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,
)

0 comments on commit f5b14b1

Please sign in to comment.