Fix unstable formatting on trailers omitted from line splitting with comments
Fixes #238
This commit is contained in:
parent
9a6c88c7f4
commit
658eb7161d
@ -664,6 +664,10 @@ More details can be found in [CONTRIBUTING](CONTRIBUTING.md).
|
|||||||
* fixed invalid code produced when stars in very long imports were incorrectly
|
* fixed invalid code produced when stars in very long imports were incorrectly
|
||||||
wrapped in optional parentheses (#234)
|
wrapped in optional parentheses (#234)
|
||||||
|
|
||||||
|
* fixed unstable formatting when inline comments were moved around in
|
||||||
|
a trailer that was omitted from line splitting on a large expression
|
||||||
|
(#238)
|
||||||
|
|
||||||
### 18.5b0
|
### 18.5b0
|
||||||
|
|
||||||
* call chains are now formatted according to the
|
* call chains are now formatted according to the
|
||||||
|
6
black.py
6
black.py
@ -2599,7 +2599,8 @@ def generate_trailers_to_omit(line: Line, line_length: int) -> Iterator[Set[Leaf
|
|||||||
if length > line_length:
|
if length > line_length:
|
||||||
break
|
break
|
||||||
|
|
||||||
if leaf.type == STANDALONE_COMMENT:
|
has_inline_comment = leaf_length > len(leaf.value) + len(leaf.prefix)
|
||||||
|
if leaf.type == STANDALONE_COMMENT or has_inline_comment:
|
||||||
break
|
break
|
||||||
|
|
||||||
optional_brackets.discard(id(leaf))
|
optional_brackets.discard(id(leaf))
|
||||||
@ -2940,9 +2941,6 @@ def enumerate_with_length(
|
|||||||
|
|
||||||
comment: Optional[Leaf]
|
comment: Optional[Leaf]
|
||||||
for comment in line.comments_after(leaf, index):
|
for comment in line.comments_after(leaf, index):
|
||||||
if "\n" in comment.prefix:
|
|
||||||
return # Oops, standalone comment!
|
|
||||||
|
|
||||||
length += len(comment.value)
|
length += len(comment.value)
|
||||||
|
|
||||||
yield index, leaf, length
|
yield index, leaf, length
|
||||||
|
@ -116,7 +116,7 @@
|
|||||||
call(**self.screen_kwargs)
|
call(**self.screen_kwargs)
|
||||||
call(b, **self.screen_kwargs)
|
call(b, **self.screen_kwargs)
|
||||||
lukasz.langa.pl
|
lukasz.langa.pl
|
||||||
@@ -93,11 +114,11 @@
|
@@ -93,23 +114,25 @@
|
||||||
1.0 .real
|
1.0 .real
|
||||||
....__class__
|
....__class__
|
||||||
list[str]
|
list[str]
|
||||||
@ -127,9 +127,27 @@
|
|||||||
very_long_variable_name_filters: t.List[
|
very_long_variable_name_filters: t.List[
|
||||||
t.Tuple[str, t.Union[str, t.List[t.Optional[str]]]],
|
t.Tuple[str, t.Union[str, t.List[t.Optional[str]]]],
|
||||||
]
|
]
|
||||||
|
xxxx_xxxxx_xxxx_xxx: Callable[..., List[SomeClass]] = classmethod( # type: ignore
|
||||||
|
sync(async_xxxx_xxx_xxxx_xxxxx_xxxx_xxx.__func__)
|
||||||
|
)
|
||||||
|
-xxxx_xxx_xxxx_xxxxx_xxxx_xxx: Callable[..., List[SomeClass]] = classmethod( # type: ignore
|
||||||
|
- sync(async_xxxx_xxx_xxxx_xxxxx_xxxx_xxx.__func__)
|
||||||
|
-)
|
||||||
|
xxxx_xxx_xxxx_xxxxx_xxxx_xxx: Callable[
|
||||||
|
..., List[SomeClass]
|
||||||
|
-] = classmethod(sync(async_xxxx_xxx_xxxx_xxxxx_xxxx_xxx.__func__)) # type: ignore
|
||||||
|
+] = classmethod( # type: ignore
|
||||||
|
+ sync(async_xxxx_xxx_xxxx_xxxxx_xxxx_xxx.__func__)
|
||||||
|
+)
|
||||||
|
+xxxx_xxx_xxxx_xxxxx_xxxx_xxx: Callable[..., List[SomeClass]] = classmethod(
|
||||||
|
+ sync(async_xxxx_xxx_xxxx_xxxxx_xxxx_xxx.__func__)
|
||||||
|
+) # type: ignore
|
||||||
slice[0]
|
slice[0]
|
||||||
slice[0:1]
|
slice[0:1]
|
||||||
@@ -124,107 +145,159 @@
|
slice[0:1:2]
|
||||||
|
slice[:]
|
||||||
|
slice[:-1]
|
||||||
|
@@ -133,107 +156,159 @@
|
||||||
numpy[-(c + 1) :, d]
|
numpy[-(c + 1) :, d]
|
||||||
numpy[:, l[-2]]
|
numpy[:, l[-2]]
|
||||||
numpy[:, ::-1]
|
numpy[:, ::-1]
|
||||||
|
@ -99,6 +99,15 @@
|
|||||||
very_long_variable_name_filters: t.List[
|
very_long_variable_name_filters: t.List[
|
||||||
t.Tuple[str, t.Union[str, t.List[t.Optional[str]]]],
|
t.Tuple[str, t.Union[str, t.List[t.Optional[str]]]],
|
||||||
]
|
]
|
||||||
|
xxxx_xxxxx_xxxx_xxx: Callable[..., List[SomeClass]] = classmethod( # type: ignore
|
||||||
|
sync(async_xxxx_xxx_xxxx_xxxxx_xxxx_xxx.__func__)
|
||||||
|
)
|
||||||
|
xxxx_xxx_xxxx_xxxxx_xxxx_xxx: Callable[..., List[SomeClass]] = classmethod( # type: ignore
|
||||||
|
sync(async_xxxx_xxx_xxxx_xxxxx_xxxx_xxx.__func__)
|
||||||
|
)
|
||||||
|
xxxx_xxx_xxxx_xxxxx_xxxx_xxx: Callable[
|
||||||
|
..., List[SomeClass]
|
||||||
|
] = classmethod(sync(async_xxxx_xxx_xxxx_xxxxx_xxxx_xxx.__func__)) # type: ignore
|
||||||
slice[0]
|
slice[0]
|
||||||
slice[0:1]
|
slice[0:1]
|
||||||
slice[0:1:2]
|
slice[0:1:2]
|
||||||
@ -354,6 +363,17 @@ async def f():
|
|||||||
very_long_variable_name_filters: t.List[
|
very_long_variable_name_filters: t.List[
|
||||||
t.Tuple[str, t.Union[str, t.List[t.Optional[str]]]],
|
t.Tuple[str, t.Union[str, t.List[t.Optional[str]]]],
|
||||||
]
|
]
|
||||||
|
xxxx_xxxxx_xxxx_xxx: Callable[..., List[SomeClass]] = classmethod( # type: ignore
|
||||||
|
sync(async_xxxx_xxx_xxxx_xxxxx_xxxx_xxx.__func__)
|
||||||
|
)
|
||||||
|
xxxx_xxx_xxxx_xxxxx_xxxx_xxx: Callable[
|
||||||
|
..., List[SomeClass]
|
||||||
|
] = classmethod( # type: ignore
|
||||||
|
sync(async_xxxx_xxx_xxxx_xxxxx_xxxx_xxx.__func__)
|
||||||
|
)
|
||||||
|
xxxx_xxx_xxxx_xxxxx_xxxx_xxx: Callable[..., List[SomeClass]] = classmethod(
|
||||||
|
sync(async_xxxx_xxx_xxxx_xxxxx_xxxx_xxx.__func__)
|
||||||
|
) # type: ignore
|
||||||
slice[0]
|
slice[0]
|
||||||
slice[0:1]
|
slice[0:1]
|
||||||
slice[0:1:2]
|
slice[0:1:2]
|
||||||
|
Loading…
Reference in New Issue
Block a user