Registry / testing / flake8-black

flake8-black

JSON →
library0.4.0pypypiunverified

flake8-black is an MIT licensed Flake8 plugin designed to integrate Black, the uncompromising code formatter, into the Flake8 ecosystem. It allows developers to validate their Python code style against Black's rules as part of their linting process, typically used in continuous integration or pre-commit hooks. The current version is 0.4.0, and it generally follows Black's release cadence for compatibility updates.

pip install flake8-black
INSTALL
IMPORT
SIG · FLAKE8-BLACK
F
flake8-black
testingpythonv0.4.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Install flake8-black along with flake8 and black. Create a .flake8 configuration file in your project root to align Flake8's settings with Black's, particularly the `max-line-length` to 88 and ignoring conflicting style checks like `E203` (whitespace before ':'), `W503` (line break before binary operator), and `E701` (multiple statements on one line, for empty classes). Then, simply run `flake8` as usual.

# my_module.py def my_function( # This line is intentionally long to trigger Black's reformatting argument_one: str, argument_two: int, ) -> None: print(f"Hello {argument_one}, your number is {argument_two}.") # .flake8 (configuration file in project root) # [flake8] # max-line-length = 88 # extend-ignore = E203, W503, E701 # To run flake8 with flake8-black: # flake8 my_module.py
flake8 --version
Debug
Known issues
gotchaBlack's formatting for slices (e.g., `foo[1:]`) includes a space before the colon, which conflicts with `pycodestyle`'s `E203` error (`whitespace before ':'`). This will cause `flake8` to fail unless `E203` is explicitly ignored in your Flake8 configuration.
fix
Add `extend-ignore = E203` to your `[flake8]` section in `.flake8`, `setup.cfg`, or `tox.ini`.
affects: All versions
gotchaBlack formats line breaks before binary operators, which aligns with PEP 8 as of April 2016. However, `flake8` has a disabled-by-default warning `W503` (`line break before binary operator`) that conflicts with this. Enabling `W503` will lead to false positives.
fix
Ensure `W503` is not enabled in your `flake8` configuration. You may consider using `W504` (`line break after binary operator`) instead if you need a similar check that is compatible with Black. If Black produces empty classes as `class Foo: ...`, it can trigger `E701`. You might need to ignore `E701` as well.
affects: All versions
breakingEarlier versions of `flake8-black` (before v0.1.2, which implicitly required `black>=19.3b0`) could fail with errors like `__call__() got an unexpected keyword argument 'target_versions'` if used with incompatible `black` versions due to `black` API changes.
fix
Upgrade `flake8-black` to the latest version and ensure `black` is at version `19.3b0` or newer. It is recommended to pin `black`'s version in your project to avoid unexpected formatting changes from future `black` updates.
affects: <0.1.2 (for flake8-black), <19.3b0 (for black)
gotcha`flake8-black` does not automatically read or respect `black`'s `include` or `exclude` settings from `pyproject.toml`. If you have files or directories that `black` ignores, you must configure `flake8` to ignore them separately using `exclude` or `per-file-ignores` in your `flake8` configuration.
fix
Duplicate `black`'s `include` and `exclude` patterns in your `flake8` configuration file (`.flake8`, `setup.cfg`, or `tox.ini`).
affects: All versions
gotchaFlake8 itself does not currently use `pyproject.toml` for its configuration. All `flake8` related settings, including those for `flake8-black` or ignoring specific codes, must be placed in a `.flake8`, `setup.cfg`, or `tox.ini` file.
fix
Ensure `flake8` configurations are in one of the supported dedicated `flake8` configuration files.
affects: All versions
gotchaThe `BLK100` error code from `flake8-black` signifies that `black` would make changes to the file. It does not reformat the file; it only reports that reformatting is needed. If you encounter `BLK100`, it means the file is not formatted according to `black`'s rules.
fix
Run `black <file_or_directory>` to reformat the code. Avoid using `# noqa: BLK100` and instead use `black`'s native pragmas like `# fmt: off`, `# fmt: on`, or `# fmt: skip` to disable formatting for specific sections or lines if absolutely necessary.
affects: All versions
Errors
Common errors & fixes
BLK100 Black would make changes
The code being linted by flake8-black is not formatted according to Black's code style, meaning Black would reformat it if run directly.
fix
Run `black .` in your project's root directory or `black your_file.py` on the specific file to automatically reformat your code to Black's style.
E203 whitespace before ':'
Black's default formatting for slice operators (e.g., `list[1:]`) includes whitespace that `pycodestyle` (a component of Flake8) flags as an E203 error.
fix
Configure Flake8 to ignore the E203 error by adding `extend-ignore = E203` to your Flake8 configuration file (e.g., `.flake8`, `setup.cfg`, or `tox.ini`).
E501 line too long
Flake8's default maximum line length is 79 characters, while Black's default maximum line length is 88 characters, leading to conflicts when both are used without matching configurations.
fix
Align Flake8's line length with Black's by setting `max-line-length = 88` in your Flake8 configuration file (e.g., `.flake8`, `setup.cfg`, or `tox.ini`).
E701 multiple statements on one line (colon)
Black formats empty class or function definitions (e.g., `class Foo: ...` or `def bar(): ...`) into a single line, which `pycodestyle` (via Flake8) flags as an E701 error.
fix
Configure Flake8 to ignore the E701 error by adding `extend-ignore = E701` to your Flake8 configuration file (e.g., `.flake8`, `setup.cfg`, or `tox.ini`).
Upgrade
Version history
0.4.0latest on PyPI · released Sep 21, 2025
Audit
Dependencies
flake8requiredCore linter that this plugin extends.
blackrequiredThe code formatter whose style rules are enforced.
Agent activity
11 hits · last 30 days
node
10
Resources
flake8-black — pip install flake8-black · libregistry