Skip to main content

More Black! - Denser Black formatting

This is a fork of the Black code formatter

Requires Python 3.10

Black itself requires Python 3.10 or later to run. It still formats code written for Python 3.3 through 3.15.

Problem

I love Black formatting because I agree with its formatting choices, but it does have one pathology: Excessive indenting on data structures

Here is an example of Black formatting; many lines are wasted on lonely brackets:

my_method(
    [
        {
            "name": "a",
            "value": 42,
        }
    ]
)

Solution: More Black!

When there is only one property (or list item, or parameter), then do not make a new line.

my_method([{
    "name": "a",
    "value": 42,
}])

Usage

Please read the official Black documentation. The command is still black, and every option works the same.

pip install mo-black

More about this fork

Three rules differ from upstream, all of them in src/black/linegen.py and src/black/brackets.py:

A bracket whose body is a single item is not split there. _body_is_lone_item() decides the body is one thing — no comma, no operator, no and/or/if/in/is at that depth — and the split descends into it instead, leaving the brackets hugged. It applies at every depth, so nested single-key dictionaries collapse together:

schema = {"mappings": {"test": {"properties": {"one_value": {
    "type": "keyword",
    "store": True,
}}}}}

Every attribute dot is a split point, not only a dot that follows a call, so a long method chain breaks before each name.

Parentheses around something already atomic are removed. not (a) becomes not a, and foo((a), (b)) becomes foo(a, b). Every slot in the grammar's precedence cascade bottoms out at atom, so parentheses around one group nothing. Parentheses that group, build a tuple, or make a generator are left alone.

Everything else is upstream Black.

Development

Be sure you are in the mo-black main directory.

Setup virtual environment

python -m venv .venv
.venv\Scripts\activate

Install the package and its test requirements

pip install -e ".[d,jupyter]" pytest pytest-xdist

Run the tests

pytest tests

Here is the same for Linux and macOS...

python -m venv .venv
source .venv/bin/activate
pip install -e ".[d,jupyter]" pytest pytest-xdist
pytest tests

Deployment

packaging/deploy.py builds the distributions and uploads them.

python packaging/deploy.py --next-version           # what the next release would be
python packaging/deploy.py --compiled --build-only  # build it all, upload nothing
python packaging/deploy.py --compiled               # and upload

The version is never written into a file: deploy.py works out the next major.minor.%y%j and hands it to the build. Uploading happens only from master, and the tag is written afterwards, once PyPI has accepted.

--compiled additionally builds the mypyc wheels, which is what makes Black fast: one per interpreter and platform, in parallel, taking around twenty minutes. Without it you get the pure-Python wheel, which formats about 1.7x slower.

Metadata

Release files for mo-black 4.6.26234

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mo-black 4.6.26234
File Size Uploaded
mo_black-4.6.26234.tar.gz 670.7 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for mo-black 4.6.26234
File
mo_black-4.6.26234-py3-none-any.whl Python 3 none any Details
mo_black-4.6.26234-cp314-cp314-win_amd64.whl CPython 3.14 CPython 3.14 Windows x86-64 Details
mo_black-4.6.26234-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl CPython 3.14 CPython 3.14 Linux glibc 2.17+ x86-64, Linux glibc 2.28+ x86-64 Details
mo_black-4.6.26234-cp313-cp313-win_amd64.whl CPython 3.13 CPython 3.13 Windows x86-64 Details
mo_black-4.6.26234-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl CPython 3.13 CPython 3.13 Linux glibc 2.17+ x86-64, Linux glibc 2.28+ x86-64 Details
mo_black-4.6.26234-cp312-cp312-win_amd64.whl CPython 3.12 CPython 3.12 Windows x86-64 Details
mo_black-4.6.26234-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl CPython 3.12 CPython 3.12 Linux glibc 2.17+ x86-64, Linux glibc 2.28+ x86-64 Details
mo_black-4.6.26234-cp311-cp311-win_amd64.whl CPython 3.11 CPython 3.11 Windows x86-64 Details
mo_black-4.6.26234-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl CPython 3.11 CPython 3.11 Linux glibc 2.28+ x86-64, Linux glibc 2.17+ x86-64 Details
mo_black-4.6.26234-cp310-cp310-win_amd64.whl CPython 3.10 CPython 3.10 Windows x86-64 Details
mo_black-4.6.26234-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl CPython 3.10 CPython 3.10 Linux glibc 2.17+ x86-64, Linux glibc 2.28+ x86-64 Details

Total release size: 18.2 MB

Release files / mo_black-4.6.26234.tar.gz

Download URL mo_black-4.6.26234.tar.gz
Size 670.7 kB
Tags Source
SHA-256 checksum
How to use checksums
3a2368b8094c91acd878711086da8368b3e430189b9e4e10b07c798934617369
BLAKE2b-256 checksum
How to use checksums
1d391be4b54f9363756bc0948ff46415e6f8f1df37e50b40230b17be3f7c20c7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.1

Release files / mo_black-4.6.26234-py3-none-any.whl

Download URL mo_black-4.6.26234-py3-none-any.whl
Size 198.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
22421f87800f98b5d91ad35cc92fb4f038d64c59256bf673b88821cf15e6d8e4
BLAKE2b-256 checksum
How to use checksums
50abdbff08e07a2e4d367c8d0103364b668b127d67ad4c3d89c8ac7beb5266d9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.1

Release files / mo_black-4.6.26234-cp314-cp314-win_amd64.whl

Download URL mo_black-4.6.26234-cp314-cp314-win_amd64.whl
Size 1.6 MB
Tags CPython 3.14 Windows x86-64
SHA-256 checksum
How to use checksums
7a3e91a144bbd32534d749b945e06115157e9b833436ad97e271932b6e100fca
BLAKE2b-256 checksum
How to use checksums
83ea541454d36d046d4921024243d5db6963ea1d779b0c9144e6aab3915d6082
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.1

Release files / mo_black-4.6.26234-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl

Download URL mo_black-4.6.26234-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Size 1.9 MB
Tags CPython 3.14 Linux glibc 2.17+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
63374844cbbb39f60def41858e8381b02776649b62bb4029cb90f7c194a28dd0
BLAKE2b-256 checksum
How to use checksums
ecc63a3c4522246db35f92f056331968f3fb72df6d6c8d7eac2a79ee909b6d82
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.1

Release files / mo_black-4.6.26234-cp313-cp313-win_amd64.whl

Download URL mo_black-4.6.26234-cp313-cp313-win_amd64.whl
Size 1.5 MB
Tags CPython 3.13 Windows x86-64
SHA-256 checksum
How to use checksums
a39a6aacc6c9e2d64427dfe3d680d7c5f0584d2da4952dba6532eecab526ac7b
BLAKE2b-256 checksum
How to use checksums
322a45808eaf7738a4bd6b78a69941aa1d28f9d943227746f06b0620262ebe3a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.1

Release files / mo_black-4.6.26234-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl

Download URL mo_black-4.6.26234-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Size 1.9 MB
Tags CPython 3.13 Linux glibc 2.17+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
d98875c32ebdb394e652f0c8ff328cfe282bfe66a0ee5644243ea3ce8d4d7347
BLAKE2b-256 checksum
How to use checksums
0b0252acb3e5b0a686bbbcb97b4dc57a4820862f620943fe823fe13f4f25a4d4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.1

Release files / mo_black-4.6.26234-cp312-cp312-win_amd64.whl

Download URL mo_black-4.6.26234-cp312-cp312-win_amd64.whl
Size 1.5 MB
Tags CPython 3.12 Windows x86-64
SHA-256 checksum
How to use checksums
10d652fd211f36e1eb9eabf45e3bd1992e3edde63e85fa723bf5828543b1eb85
BLAKE2b-256 checksum
How to use checksums
0f0f8f2c25c62555b50f8000125634d2faa80404b299ce999f044cc85cd3485a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.1

Release files / mo_black-4.6.26234-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl

Download URL mo_black-4.6.26234-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Size 2.0 MB
Tags CPython 3.12 Linux glibc 2.17+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
bc0415bac890dab393a541f86361ce0b0ae52c767006f3fb45821ee8cf2133a3
BLAKE2b-256 checksum
How to use checksums
7e7b0b89dc634e10f99f00126fb58261eb541cc14e10c4ce79d03b3501052e8d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.1

Release files / mo_black-4.6.26234-cp311-cp311-win_amd64.whl

Download URL mo_black-4.6.26234-cp311-cp311-win_amd64.whl
Size 1.5 MB
Tags CPython 3.11 Windows x86-64
SHA-256 checksum
How to use checksums
3a7b1cb64fcb9e0be88293843abeb42ae707d814acb6963654b374dfbd6c90ee
BLAKE2b-256 checksum
How to use checksums
4b15df3d8f42d889318e102566f093a85d1899fb7ae4c586e41c8f53e18155a5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.1

Release files / mo_black-4.6.26234-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl

Download URL mo_black-4.6.26234-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Size 1.9 MB
Tags CPython 3.11 Linux glibc 2.17+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
97d9333be3bad77e64699b0fdb599b13d80951f24395f02a13e141d03685324e
BLAKE2b-256 checksum
How to use checksums
e78d498264f9619e94fde57174633aad5021a4dd02844f3247868027693d0753
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.1

Release files / mo_black-4.6.26234-cp310-cp310-win_amd64.whl

Download URL mo_black-4.6.26234-cp310-cp310-win_amd64.whl
Size 1.5 MB
Tags CPython 3.10 Windows x86-64
SHA-256 checksum
How to use checksums
4a29ffe3f6f2055f7ba98359e06f5eb1533739187577dbb1db73862bfac7bc3f
BLAKE2b-256 checksum
How to use checksums
703b101158172809bae9d67c9c0fea6df37ef57607cf69288c02d240f25a1a07
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.1

Release files / mo_black-4.6.26234-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl

Download URL mo_black-4.6.26234-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Size 1.9 MB
Tags CPython 3.10 Linux glibc 2.17+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
eb499f733f7ac0e55eb8b5ebefce677cc0fa99310514253366ba280049d8575c
BLAKE2b-256 checksum
How to use checksums
cc695dbd962d5687920628652f32c6c416c1aef2cedc366b9bb860ed4abaa65c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.1

Release history Release notifications | RSS feed

This release

4.6.26234 This release

12 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page