Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
28034ee
Add preview feature for consistent blank lines around overload groups…
AlexWaygood Mar 3, 2026
d7c4c6c
Broaden overload group heuristic to apply regardless of adjacent stat…
AlexWaygood Mar 3, 2026
afdc650
docs
AlexWaygood Mar 3, 2026
1280c7a
format
AlexWaygood Mar 3, 2026
1df33b6
.
AlexWaygood Mar 3, 2026
32392c7
schema
AlexWaygood Mar 3, 2026
9540cbc
Merge branch 'better-stub-formatting-2' of https://github.com/AlexWay…
AlexWaygood Mar 3, 2026
29f31bd
improve docs
AlexWaygood Mar 3, 2026
c40e0cb
Address review to limit the changes to only groups of >=1 same-named …
AlexWaygood Mar 4, 2026
71f6243
fixup docs per review
AlexWaygood Mar 4, 2026
f88aeb2
revert change to `test_black.py`
AlexWaygood Mar 4, 2026
50072ba
factor out a helper method and fix edge cases involving comments in b…
AlexWaygood Mar 4, 2026
a86506b
format
AlexWaygood Mar 4, 2026
b3ad971
refactor helpers and add tests for comments near overload groups
AlexWaygood Mar 4, 2026
15809a2
fix bug highlighted by diff-shades
AlexWaygood Mar 4, 2026
add21ae
fix edge cases: 3+ stub overloads, blank lines around if/else blocks
AlexWaygood Mar 4, 2026
b4277b7
nits
AlexWaygood Mar 4, 2026
43fd521
simplifications
AlexWaygood Mar 5, 2026
a823c88
Merge branch 'main' into better-stub-formatting-2
AlexWaygood Mar 11, 2026
ae32bed
.
AlexWaygood Mar 11, 2026
3f976c6
.
AlexWaygood Mar 11, 2026
8ed13f5
simplifications and more tests
AlexWaygood Mar 12, 2026
9e23f32
Merge branch 'better-stub-formatting-2' of https://github.com/AlexWay…
AlexWaygood Mar 12, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@

<!-- Changes that affect Black's preview style -->

- Improve heuristics around whether blank lines should appear before, within and after
groups of same-name decorated functions (such as `@overload` groups) in `.pyi` stub
files (#5021)

### Configuration

<!-- Changes to how Black can be configured -->
Expand Down
52 changes: 52 additions & 0 deletions docs/the_black_code_style/future_style.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ Currently, the following features are included in the preview style:
- `fix_if_guard_explosion_in_case_statement`: fixed exploding of the if guard in case
patterns which have trailing commas in them, even if the guard expression fits in one
line
- `pyi_overload_group_blank_lines`: In `.pyi` stub files, improve heuristics around when
blank lines should appear before, after and within decorated function groups.
([see below](labels/pyi-overload-group))

(labels/wrap-comprehension-in)=

Expand Down Expand Up @@ -137,6 +140,55 @@ my_dict = {
}
```

(labels/pyi-overload-group)=

### Improved overload groups in stub files

In `.pyi` stub files, Black now has improved heuristics regarding when blank lines
should appear before, after or within groups of decorated functions that share the same
name (such as `@overload` groups). Two rules are applied when a decorated function is
determined to be part of a series of >=2 decorated functions with the same name:

1. **Before the decorated function**: a blank line is always inserted, unless the
preceding statement is a same-name decorated function (i.e. part of an `@overload`
group) or the function is the first statement in its block.
2. **After the decorated function**: a blank line is always inserted, unless the
following statement is a same-name decorated function.

These rules apply regardless of what the adjacent statement is — whether it's another
function definition, a variable annotation, or any other statement.

Previously, Black could insert unwanted blank lines _within_ an overload group when one
of the overloads had a docstring, and did not consistently enforce blank lines at the
boundaries of overload groups:

```python
# Before

@overload
def foo(x: int) -> int:
"""Docs."""

@overload # unwanted blank line within group
def foo(x: str) -> str: ...
def bar(x): ... # no blank line after group
```

With this feature enabled, the group is kept together and clearly separated from
surrounding code:

```python
# After (with --preview)

@overload
def foo(x: int) -> int:
"""Docs."""
@overload
def foo(x: str) -> str: ...

def bar(x): ...
```

## Unstable style

(labels/unstable-style)=
Expand Down
Loading
Loading