{"id":5226,"library":"flake8-black","title":"Flake8 Black Plugin","description":"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.","status":"active","version":"0.4.0","language":"en","source_language":"en","source_url":"https://github.com/peterjc/flake8-black","tags":["flake8","black","linter","code-quality","style-checker","formatter-plugin"],"install":[{"cmd":"pip install flake8-black","lang":"bash","label":"Install with pip"}],"dependencies":[{"reason":"Core linter that this plugin extends.","package":"flake8","optional":false},{"reason":"The code formatter whose style rules are enforced.","package":"black","optional":false}],"imports":[],"quickstart":{"code":"# my_module.py\n\ndef my_function(  # This line is intentionally long to trigger Black's reformatting\n    argument_one: str,\n    argument_two: int,\n) -> None:\n    print(f\"Hello {argument_one}, your number is {argument_two}.\")\n\n\n# .flake8 (configuration file in project root)\n# [flake8]\n# max-line-length = 88\n# extend-ignore = E203, W503, E701\n\n# To run flake8 with flake8-black:\n# flake8 my_module.py","lang":"python","description":"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."},"warnings":[{"fix":"Add `extend-ignore = E203` to your `[flake8]` section in `.flake8`, `setup.cfg`, or `tox.ini`.","message":"Black'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.","severity":"gotcha","affected_versions":"All versions"},{"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.","message":"Black 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.","severity":"gotcha","affected_versions":"All versions"},{"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.","message":"Earlier 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.","severity":"breaking","affected_versions":"<0.1.2 (for flake8-black), <19.3b0 (for black)"},{"fix":"Duplicate `black`'s `include` and `exclude` patterns in your `flake8` configuration file (`.flake8`, `setup.cfg`, or `tox.ini`).","message":"`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.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Ensure `flake8` configurations are in one of the supported dedicated `flake8` configuration files.","message":"Flake8 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.","severity":"gotcha","affected_versions":"All versions"},{"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.","message":"The `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.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-13T00:00:00.000Z","next_check":"2026-07-12T00:00:00.000Z"}