]> git.madduck.net Git - etc/vim.git/commitdiff

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

Remove the trailing comma if there is only one argument to a call
authorŁukasz Langa <lukasz@langa.pl>
Sat, 17 Mar 2018 00:32:55 +0000 (17:32 -0700)
committerŁukasz Langa <lukasz@langa.pl>
Sat, 17 Mar 2018 00:32:55 +0000 (17:32 -0700)
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.

README.md
black.py
tests/expression.py
tests/function.py

index c1fd95ab5fccdf3722a3eec80382257fc826f337..69616ff5f4c6796d56f8ccbc7a27b580628c1989 100644 (file)
--- a/README.md
+++ b/README.md
@@ -260,6 +260,11 @@ More details can be found in [CONTRIBUTING](CONTRIBUTING.md).
 
 ### 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 spurious space after star-based unary expressions (#31)
index b343da7b6d7363e52bc4a29e8715b247886a6a02..27691ddaeb1a78e2912a51ee2a5065980ed7e89d 100644 (file)
--- a/black.py
+++ b/black.py
@@ -508,6 +508,10 @@ class Line:
             bracket_depth = leaf.bracket_depth
             if bracket_depth == depth and leaf.type == token.COMMA:
                 commas += 1
+                if leaf.parent and leaf.parent.type == syms.arglist:
+                    commas += 1
+                    break
+
         if commas > 1:
             self.leaves.pop()
             return True
@@ -1480,7 +1484,7 @@ def assert_equivalent(src: str, dst: str) -> None:
         raise AssertionError(
             f"INTERNAL ERROR: Black produced invalid code: {exc}. "
             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
 
     src_ast_str = '\n'.join(_v(src_ast))
@@ -1491,7 +1495,7 @@ def assert_equivalent(src: str, dst: str) -> None:
             f"INTERNAL ERROR: Black produced code that is not equivalent to "
             f"the source.  "
             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
 
 
@@ -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"of the formatter.  "
             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
 
 
index 2e7f2750e7dd2e3ea934b3da26d6330cf727dac6..e7054e34f929bad2857a96ea96675a2c56ff8270 100644 (file)
@@ -106,15 +106,15 @@ a = (1,)
 b = 1,
 c = 1
 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)
-
+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():
     yield from outside_of_generator
     a = (yield)
 
-
 async def f():
     await some.complicated[0].call(with_args=(True or (1 is not 1)))
 
@@ -239,12 +239,18 @@ a = (1,)
 b = 1,
 c = 1
 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
 )
+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():
index 29de4086a7b8cf973a35afab2e7528cb3fdbe118..7fa6866bdd70fb3e8297a1ab77ec9d36689a57c5 100644 (file)
@@ -37,7 +37,7 @@ def example(session):
         models.Customer.account_id == account_id,
         models.Customer.email == email_address,
     ).order_by(
-        models.Customer.id.asc(),
+        models.Customer.id.asc()
     ).all()
 def long_lines():
     if True:
@@ -129,7 +129,7 @@ def example(session):
     result = session.query(models.Customer.id).filter(
         models.Customer.account_id == account_id, models.Customer.email == email_address
     ).order_by(
-        models.Customer.id.asc(),
+        models.Customer.id.asc()
     ).all()