Correct placement of separators
Project description
flake8-digit-separator
A set of rules on top of the capabilities provided by PEP515.
correct_int = 10_000
correct_float = 10_000.1_234
correct_binary = 0b_1101_1001
correct_octal = 0o_134_155
correct_hex = 0x_CAFE_F00D
Installation
pip install flake8-digit-separator
Usage
flake8 ./ --select FDS
Rules
PEP515 allows separators, but does not impose any restrictions on their position in a number (except that a number should not start/end with a separator and there should not be two separators in a row). To introduce more rigor and beauty into the code, we have written a few simple rules that we suggest following.
| Rule | Number | Description | Correct | Wrong |
|---|---|---|---|---|
| FDS100 | integer | Group by 3s from right | 10_000 | 10_0 |
| FDS200 | float | Group by 3s from right | 10_000.1_234 | 1_0_0.123_4 |
| FDS300 | binary | Group by 4s from right after prefix 0b_ |
0b_1101_1001 | 0b110_11 |
| FDS400 | octal | Group by 3s from right after prefix 0o_ |
0o_12_134_155 | 0o1_23_45 |
| FDS500 | hex | Group by 4s from right after prefix 0x_ |
0x_CAFE_F00D | 0xCAFEF0_0D |
Configuration Options
--fds-exclude
Exclude specific integer numbers from digit separator validation. This is useful for well-known numbers like ports or other constants where the standard formatting might not be appropriate. For example, when we write port = 8080 or storage = 1024, there is no point in distorting it through 8_080 or through 1_024.
Use the option:
flake8 ./ --select FDS --fds-exclude=8080,1024,6379
Or configure in setup.cfg:
[flake8]
fds-exclude = 8080,1024,6379
License
FDS is released under the MIT License. See the bundled LICENSE file for details.
The logo was created using Font Meme.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file flake8_digit_separator-1.0.4.tar.gz.
File metadata
- Download URL: flake8_digit_separator-1.0.4.tar.gz
- Upload date:
- Size: 11.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.3 CPython/3.13.5 Darwin/23.6.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cd9cfa077fd8b83e42391464cc4a28b681e79502cdf99000adab5e9e53c0a98a
|
|
| MD5 |
fd61521382586183402bf515ab6510d6
|
|
| BLAKE2b-256 |
9462b50349c2583b1c39ffa123c91b46e2ce4db2c70bc2166a2811283cfe4379
|
File details
Details for the file flake8_digit_separator-1.0.4-py3-none-any.whl.
File metadata
- Download URL: flake8_digit_separator-1.0.4-py3-none-any.whl
- Upload date:
- Size: 22.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.3 CPython/3.13.5 Darwin/23.6.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8aec7bf52590db648d1c73db0f6537db0c79e83d906d20a26a4f9f9e02118956
|
|
| MD5 |
d8c9c618c4024aab2b4f79742d3cc785
|
|
| BLAKE2b-256 |
94076775ec7970ba1bec543b46d85ed6e3a605ab3dbb2ecb979df5b9f497e486
|