yapf icon indicating copy to clipboard operation
yapf copied to clipboard

DEDENT_CLOSING_BRACKETS doesn't always dedent

Open WhyNotHugo opened this issue 5 years ago • 3 comments

I've DEDENT_CLOSING_BRACKETS = true, and it most of the times, but not sometimes.

Here's a change that yapf applies:

@@ -942,13 +934,12 @@ class Order(BaseOrder):
             paths[link_name] = target

             for image in p.product.images.all():
-                link_name = (
-                    '{product}/P-{order}/originals/{filename}'
-                ).format(
-                    product=p.product_name,
-                    order=self.pk,
-                    filename=image.photo.original_filename,
-                )
+                link_name = ('{product}/P-{order}/originals/{filename}'
+                             ).format(
+                                 product=p.product_name,
+                                 order=self.pk,
+                                 filename=image.photo.original_filename,
+                             )
                 target = image.photo.image
                 paths[link_name] = target

I think that becuase ).format doesn't fit in this line, it moves it into the next (although the arguments and the closing bracket by themselves do fit), but doesn't respect dedenting.

WhyNotHugo avatar May 11 '20 17:05 WhyNotHugo

I also tried setting SPLIT_BEFORE_DOT, but it renders the same result -- even though the closing bracket should be placed in the first line in this case.

WhyNotHugo avatar May 11 '20 17:05 WhyNotHugo

Also for assigning returned multiple results of a function call:

a, b = func(arg1,
                  arg2,
                  arg3)

is expected to format to this:

a, b = func(
    arg1,
    arg2,
    arg3
)

but it does not

kliyes avatar Jun 17 '20 01:06 kliyes

Another sample, and fiddling notes:

Result one:

cast_to_bool = SwitchAttr(('bool', 'b'),
                          list=True,
                          argname='YAMLPATH',
                          help="Cast any nodes matching the given YAML Path query as booleans")

This is achieved with the following config:

coalesce_brackets = true
dedent_closing_brackets = true
column_limit = 99

If we remove either or both of column_limit and coalesce_brackets, we get result two:

cast_to_bool = SwitchAttr(
    ('bool', 'b'),
    list=True,
    argname='YAMLPATH',
    help="Cast any nodes matching the given YAML Path query as booleans"
)

AndydeCleyre avatar Sep 17 '22 03:09 AndydeCleyre