A wrapper for black adding new features
Project description
Globality black
A wrapper for black, adding pre- and post-processing to better align with Globality conventions.
globality-black
performs the following steps:
- pre-processing: to protect from black actions.
- black
- postprocessing: to revert / correct black actions.
Features
Blank lines
Black would remove those blank lines after wandb
and scikit-learn
below:
graph.use(
"wandb",
"scikit-learn",
# we love pandas
"pandas",
)
globality-black
protects those assuming the developer added them for readability.
Comprehensions
Explode comprehensions
- all dict comprehensions
- any comprehension with an if
- list / set comprehensions where the element has a ternary operator (see examples below)
For everything else, we rely on black
. Examples:
Before globality-black
[3 for _ in range(10)]
[3 for i in range(10) if i < 4]
{"a": 3 for _ in range(4)}
{"a": 3 for _ in range(4) if i < 4}
["odd" if i %% 2 == 0 else "even" for _ in range(10)]
After globality-black
[3 for _ in range(10)]
[
3
for i in range(10)
if i < 4
]
{
"a": 3
for _ in range(4)
}
{
"a": 3
for _ in range(4)
if i < 4
}
[
"odd" if i %% 2 == 0 else "even"
for _ in range(10)
]
Partially disable globality-black
If you see some block where you don't want to apply globality-black
, wrap it
with # fmt.off
and # fmt:on
and it will be ignored. Note that this is the same syntax as
for black
. For example, some complex comprehensions
are not covered yet, so you might want to do something as:
# fmt: off
files_to_read = [
(f"{key1}_{key2}", key1 + key2)
for key1 in range(10)
for key2 in range(10)
]
# fmt: on
See known_failed_comprehensions
for more examples.
Pending / Future work
- Fix known_failures, mainly to cover all comprehensions
=============== Globality black
v0.1.0
- TODO
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Hashes for globality-black-2021.1.356.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 91dc44528406879a75f85c37c5b1163788f0203461c304440a23dd952f98cb34 |
|
MD5 | 503ada313c38b5d13d3c4ebcfd5c7f1c |
|
BLAKE2b-256 | 7b3211ecdde381d0a148555343abcbf49e69f4595d9bd53aed6f6f4333e29306 |