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.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mo_black-4.6.26234.tar.gz (670.7 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

mo_black-4.6.26234-py3-none-any.whl (198.1 kB view details)

Uploaded Python 3

mo_black-4.6.26234-cp314-cp314-win_amd64.whl (1.6 MB view details)

Uploaded CPython 3.14Windows x86-64

mo_black-4.6.26234-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (1.9 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.17+ x86-64manylinux: glibc 2.28+ x86-64

mo_black-4.6.26234-cp313-cp313-win_amd64.whl (1.5 MB view details)

Uploaded CPython 3.13Windows x86-64

mo_black-4.6.26234-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (1.9 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64manylinux: glibc 2.28+ x86-64

mo_black-4.6.26234-cp312-cp312-win_amd64.whl (1.5 MB view details)

Uploaded CPython 3.12Windows x86-64

mo_black-4.6.26234-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (2.0 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64manylinux: glibc 2.28+ x86-64

mo_black-4.6.26234-cp311-cp311-win_amd64.whl (1.5 MB view details)

Uploaded CPython 3.11Windows x86-64

mo_black-4.6.26234-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (1.9 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64manylinux: glibc 2.28+ x86-64

mo_black-4.6.26234-cp310-cp310-win_amd64.whl (1.5 MB view details)

Uploaded CPython 3.10Windows x86-64

mo_black-4.6.26234-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (1.9 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64manylinux: glibc 2.28+ x86-64

File details

Details for the file mo_black-4.6.26234.tar.gz.

File metadata

  • Download URL: mo_black-4.6.26234.tar.gz
  • Upload date:
  • Size: 670.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.1

File hashes

Hashes for mo_black-4.6.26234.tar.gz
Algorithm Hash digest
SHA256 3a2368b8094c91acd878711086da8368b3e430189b9e4e10b07c798934617369
MD5 b5725768fdb55fd0a11955ff4019a495
BLAKE2b-256 1d391be4b54f9363756bc0948ff46415e6f8f1df37e50b40230b17be3f7c20c7

See more details on using hashes here.

File details

Details for the file mo_black-4.6.26234-py3-none-any.whl.

File metadata

  • Download URL: mo_black-4.6.26234-py3-none-any.whl
  • Upload date:
  • Size: 198.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.1

File hashes

Hashes for mo_black-4.6.26234-py3-none-any.whl
Algorithm Hash digest
SHA256 22421f87800f98b5d91ad35cc92fb4f038d64c59256bf673b88821cf15e6d8e4
MD5 5f48cc398cc3e578d02b18025e6f0c59
BLAKE2b-256 50abdbff08e07a2e4d367c8d0103364b668b127d67ad4c3d89c8ac7beb5266d9

See more details on using hashes here.

File details

Details for the file mo_black-4.6.26234-cp314-cp314-win_amd64.whl.

File metadata

File hashes

Hashes for mo_black-4.6.26234-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 7a3e91a144bbd32534d749b945e06115157e9b833436ad97e271932b6e100fca
MD5 07250ae33897b1afec2788e3c2da2eaa
BLAKE2b-256 83ea541454d36d046d4921024243d5db6963ea1d779b0c9144e6aab3915d6082

See more details on using hashes here.

File details

Details for the file mo_black-4.6.26234-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for mo_black-4.6.26234-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 63374844cbbb39f60def41858e8381b02776649b62bb4029cb90f7c194a28dd0
MD5 3f0be18cf3540d4e17991b285d5d479b
BLAKE2b-256 ecc63a3c4522246db35f92f056331968f3fb72df6d6c8d7eac2a79ee909b6d82

See more details on using hashes here.

File details

Details for the file mo_black-4.6.26234-cp313-cp313-win_amd64.whl.

File metadata

File hashes

Hashes for mo_black-4.6.26234-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 a39a6aacc6c9e2d64427dfe3d680d7c5f0584d2da4952dba6532eecab526ac7b
MD5 5718065be53955cbb8904df8e82d1121
BLAKE2b-256 322a45808eaf7738a4bd6b78a69941aa1d28f9d943227746f06b0620262ebe3a

See more details on using hashes here.

File details

Details for the file mo_black-4.6.26234-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for mo_black-4.6.26234-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 d98875c32ebdb394e652f0c8ff328cfe282bfe66a0ee5644243ea3ce8d4d7347
MD5 4fe0d15ae1bb0a293fb0a0f2e211bd34
BLAKE2b-256 0b0252acb3e5b0a686bbbcb97b4dc57a4820862f620943fe823fe13f4f25a4d4

See more details on using hashes here.

File details

Details for the file mo_black-4.6.26234-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for mo_black-4.6.26234-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 10d652fd211f36e1eb9eabf45e3bd1992e3edde63e85fa723bf5828543b1eb85
MD5 9917f9201b1f7046e1f1c02d279a8862
BLAKE2b-256 0f0f8f2c25c62555b50f8000125634d2faa80404b299ce999f044cc85cd3485a

See more details on using hashes here.

File details

Details for the file mo_black-4.6.26234-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for mo_black-4.6.26234-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 bc0415bac890dab393a541f86361ce0b0ae52c767006f3fb45821ee8cf2133a3
MD5 f3964c117b53830e730146590ba5320b
BLAKE2b-256 7e7b0b89dc634e10f99f00126fb58261eb541cc14e10c4ce79d03b3501052e8d

See more details on using hashes here.

File details

Details for the file mo_black-4.6.26234-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for mo_black-4.6.26234-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 3a7b1cb64fcb9e0be88293843abeb42ae707d814acb6963654b374dfbd6c90ee
MD5 fb372f33b4a8f311787d52b46eac3b4d
BLAKE2b-256 4b15df3d8f42d889318e102566f093a85d1899fb7ae4c586e41c8f53e18155a5

See more details on using hashes here.

File details

Details for the file mo_black-4.6.26234-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for mo_black-4.6.26234-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 97d9333be3bad77e64699b0fdb599b13d80951f24395f02a13e141d03685324e
MD5 f260c747fd598c534c5bc6ddeeae020e
BLAKE2b-256 e78d498264f9619e94fde57174633aad5021a4dd02844f3247868027693d0753

See more details on using hashes here.

File details

Details for the file mo_black-4.6.26234-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for mo_black-4.6.26234-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 4a29ffe3f6f2055f7ba98359e06f5eb1533739187577dbb1db73862bfac7bc3f
MD5 d1a9a1076f9b8bb0aeca26065453d773
BLAKE2b-256 703b101158172809bae9d67c9c0fea6df37ef57607cf69288c02d240f25a1a07

See more details on using hashes here.

File details

Details for the file mo_black-4.6.26234-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for mo_black-4.6.26234-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 eb499f733f7ac0e55eb8b5ebefce677cc0fa99310514253366ba280049d8575c
MD5 0d6bddf7a0c6c77ca71dbfd118030d67
BLAKE2b-256 cc695dbd962d5687920628652f32c6c416c1aef2cedc366b9bb860ed4abaa65c

See more details on using hashes here.

Release history Release notifications | RSS feed

22.364.23070

1 file

This release

4.6.26234 This release

12 files

4.5.26234

2 files

3.90.20218

1 file

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