| 1 |
# The Black Code Style |
| 2 |
|
| 3 |
```{toctree} |
| 4 |
--- |
| 5 |
hidden: |
| 6 |
--- |
| 7 |
|
| 8 |
Current style <current_style> |
| 9 |
Future style <future_style> |
| 10 |
``` |
| 11 |
|
| 12 |
_Black_ is a PEP 8 compliant opinionated formatter with its own style. |
| 13 |
|
| 14 |
While keeping the style unchanged throughout releases has always been a goal, the |
| 15 |
_Black_ code style isn't set in stone. It evolves to accommodate for new features in the |
| 16 |
Python language and, occasionally, in response to user feedback. Large-scale style |
| 17 |
preferences presented in {doc}`current_style` are very unlikely to change, but minor |
| 18 |
style aspects and details might change according to the stability policy presented |
| 19 |
below. Ongoing style considerations are tracked on GitHub with the |
| 20 |
[style](https://github.com/psf/black/labels/T%3A%20style) issue label. |
| 21 |
|
| 22 |
(labels/stability-policy)= |
| 23 |
|
| 24 |
## Stability Policy |
| 25 |
|
| 26 |
The following policy applies for the _Black_ code style, in non pre-release versions of |
| 27 |
_Black_: |
| 28 |
|
| 29 |
- If code has been formatted with _Black_, it will remain unchanged when formatted with |
| 30 |
the same options using any other release in the same calendar year. |
| 31 |
|
| 32 |
This means projects can safely use `black ~= 26.0` without worrying about formatting |
| 33 |
changes disrupting their project in 2026. We may still fix bugs where _Black_ crashes |
| 34 |
on some code, and make other improvements that do not affect formatting. |
| 35 |
|
| 36 |
In rare cases, we may make changes affecting code that has not been previously |
| 37 |
formatted with _Black_. For example, we have had bugs where we accidentally removed |
| 38 |
some comments. Such bugs can be fixed without breaking the stability policy. |
| 39 |
|
| 40 |
- The first release in a new calendar year _may_ contain formatting changes, although |
| 41 |
these will be minimised as much as possible. This is to allow for improved formatting |
| 42 |
enabled by newer Python language syntax as well as due to improvements in the |
| 43 |
formatting logic. |
| 44 |
|
| 45 |
- The `--preview` and `--unstable` flags are exempt from this policy. There are no |
| 46 |
guarantees around the stability of the output with these flags passed into _Black_. |
| 47 |
They are intended for allowing experimentation with proposed changes to the _Black_ |
| 48 |
code style. The `--preview` style at the end of a year should closely match the stable |
| 49 |
style for the next year, but we may always make changes. |
| 50 |
|
| 51 |
Documentation for both the current and future styles can be found: |
| 52 |
|
| 53 |
- {doc}`current_style` |
| 54 |
- {doc}`future_style` |