Remove the trailing comma if there is only one argument to a call
This makes it consistent with removing the trailing comma when multiple arguments to a call fit in a single line. It also makes it a tiny bit more likely that an expression will fit a line that didn't use to.
This commit is contained in:
parent
6ba615092e
commit
9c9f6eb6d5
@ -260,6 +260,11 @@ More details can be found in [CONTRIBUTING](CONTRIBUTING.md).
|
|||||||
|
|
||||||
### 18.3a2 (unreleased)
|
### 18.3a2 (unreleased)
|
||||||
|
|
||||||
|
* ignore empty bracket pairs while splitting. This avoids very weirdly
|
||||||
|
looking formattings (#34, #35)
|
||||||
|
|
||||||
|
* remove a trailing comma if there is a single argument to a call
|
||||||
|
|
||||||
* fixed missing space in numpy-style array indexing (#33)
|
* fixed missing space in numpy-style array indexing (#33)
|
||||||
|
|
||||||
* fixed spurious space after star-based unary expressions (#31)
|
* fixed spurious space after star-based unary expressions (#31)
|
||||||
|
10
black.py
10
black.py
@ -508,6 +508,10 @@ def maybe_remove_trailing_comma(self, closing: Leaf) -> bool:
|
|||||||
bracket_depth = leaf.bracket_depth
|
bracket_depth = leaf.bracket_depth
|
||||||
if bracket_depth == depth and leaf.type == token.COMMA:
|
if bracket_depth == depth and leaf.type == token.COMMA:
|
||||||
commas += 1
|
commas += 1
|
||||||
|
if leaf.parent and leaf.parent.type == syms.arglist:
|
||||||
|
commas += 1
|
||||||
|
break
|
||||||
|
|
||||||
if commas > 1:
|
if commas > 1:
|
||||||
self.leaves.pop()
|
self.leaves.pop()
|
||||||
return True
|
return True
|
||||||
@ -1480,7 +1484,7 @@ def _v(node: ast.AST, depth: int = 0) -> Iterator[str]:
|
|||||||
raise AssertionError(
|
raise AssertionError(
|
||||||
f"INTERNAL ERROR: Black produced invalid code: {exc}. "
|
f"INTERNAL ERROR: Black produced invalid code: {exc}. "
|
||||||
f"Please report a bug on https://github.com/ambv/black/issues. "
|
f"Please report a bug on https://github.com/ambv/black/issues. "
|
||||||
f"This invalid output might be helpful: {log}",
|
f"This invalid output might be helpful: {log}"
|
||||||
) from None
|
) from None
|
||||||
|
|
||||||
src_ast_str = '\n'.join(_v(src_ast))
|
src_ast_str = '\n'.join(_v(src_ast))
|
||||||
@ -1491,7 +1495,7 @@ def _v(node: ast.AST, depth: int = 0) -> Iterator[str]:
|
|||||||
f"INTERNAL ERROR: Black produced code that is not equivalent to "
|
f"INTERNAL ERROR: Black produced code that is not equivalent to "
|
||||||
f"the source. "
|
f"the source. "
|
||||||
f"Please report a bug on https://github.com/ambv/black/issues. "
|
f"Please report a bug on https://github.com/ambv/black/issues. "
|
||||||
f"This diff might be helpful: {log}",
|
f"This diff might be helpful: {log}"
|
||||||
) from None
|
) from None
|
||||||
|
|
||||||
|
|
||||||
@ -1510,7 +1514,7 @@ def assert_stable(src: str, dst: str, line_length: int) -> None:
|
|||||||
f"INTERNAL ERROR: Black produced different code on the second pass "
|
f"INTERNAL ERROR: Black produced different code on the second pass "
|
||||||
f"of the formatter. "
|
f"of the formatter. "
|
||||||
f"Please report a bug on https://github.com/ambv/black/issues. "
|
f"Please report a bug on https://github.com/ambv/black/issues. "
|
||||||
f"This diff might be helpful: {log}",
|
f"This diff might be helpful: {log}"
|
||||||
) from None
|
) from None
|
||||||
|
|
||||||
|
|
||||||
|
@ -106,15 +106,15 @@
|
|||||||
b = 1,
|
b = 1,
|
||||||
c = 1
|
c = 1
|
||||||
d = (1,) + a + (2,)
|
d = (1,) + a + (2,)
|
||||||
|
e = (1,).count(1)
|
||||||
what_is_up_with_those_new_coord_names = (coord_names + set(vars_to_create)) + set(vars_to_remove)
|
what_is_up_with_those_new_coord_names = (coord_names + set(vars_to_create)) + set(vars_to_remove)
|
||||||
what_is_up_with_those_new_coord_names = (coord_names | set(vars_to_create)) - set(vars_to_remove)
|
what_is_up_with_those_new_coord_names = (coord_names | set(vars_to_create)) - set(vars_to_remove)
|
||||||
|
result = session.query(models.Customer.id).filter(models.Customer.account_id == account_id, models.Customer.email == email_address).order_by(models.Customer.id.asc(),).all()
|
||||||
|
|
||||||
def gen():
|
def gen():
|
||||||
yield from outside_of_generator
|
yield from outside_of_generator
|
||||||
a = (yield)
|
a = (yield)
|
||||||
|
|
||||||
|
|
||||||
async def f():
|
async def f():
|
||||||
await some.complicated[0].call(with_args=(True or (1 is not 1)))
|
await some.complicated[0].call(with_args=(True or (1 is not 1)))
|
||||||
|
|
||||||
@ -239,12 +239,18 @@ async def f():
|
|||||||
b = 1,
|
b = 1,
|
||||||
c = 1
|
c = 1
|
||||||
d = (1,) + a + (2,)
|
d = (1,) + a + (2,)
|
||||||
|
e = (1,).count(1)
|
||||||
what_is_up_with_those_new_coord_names = (coord_names + set(vars_to_create)) + set(
|
what_is_up_with_those_new_coord_names = (coord_names + set(vars_to_create)) + set(
|
||||||
vars_to_remove
|
vars_to_remove
|
||||||
)
|
)
|
||||||
what_is_up_with_those_new_coord_names = (coord_names | set(vars_to_create)) - set(
|
what_is_up_with_those_new_coord_names = (coord_names | set(vars_to_create)) - set(
|
||||||
vars_to_remove
|
vars_to_remove
|
||||||
)
|
)
|
||||||
|
result = session.query(models.Customer.id).filter(
|
||||||
|
models.Customer.account_id == account_id, models.Customer.email == email_address
|
||||||
|
).order_by(
|
||||||
|
models.Customer.id.asc()
|
||||||
|
).all()
|
||||||
|
|
||||||
|
|
||||||
def gen():
|
def gen():
|
||||||
|
@ -37,7 +37,7 @@ def example(session):
|
|||||||
models.Customer.account_id == account_id,
|
models.Customer.account_id == account_id,
|
||||||
models.Customer.email == email_address,
|
models.Customer.email == email_address,
|
||||||
).order_by(
|
).order_by(
|
||||||
models.Customer.id.asc(),
|
models.Customer.id.asc()
|
||||||
).all()
|
).all()
|
||||||
def long_lines():
|
def long_lines():
|
||||||
if True:
|
if True:
|
||||||
@ -129,7 +129,7 @@ def example(session):
|
|||||||
result = session.query(models.Customer.id).filter(
|
result = session.query(models.Customer.id).filter(
|
||||||
models.Customer.account_id == account_id, models.Customer.email == email_address
|
models.Customer.account_id == account_id, models.Customer.email == email_address
|
||||||
).order_by(
|
).order_by(
|
||||||
models.Customer.id.asc(),
|
models.Customer.id.asc()
|
||||||
).all()
|
).all()
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user