Flake8 Broken Line
flake8-broken-line is a Flake8 plugin that enforces a coding style prohibiting the use of backslashes for line breaks in Python code. It helps maintain code readability and consistency by encouraging alternative line-breaking conventions, such as using parentheses for implicit line joining. The current version is 1.0.0, and it maintains a moderate release cadence, with updates typically focusing on Python and Flake8 compatibility.
Warnings
- breaking Older versions of `flake8-broken-line` may not be compatible with newer major versions of `flake8`. For example, versions prior to 0.4.0 might not support `flake8` 4.x, and versions prior to 0.5.0 might not support `flake8` 5.x.
- gotcha Versions of `flake8-broken-line` prior to 0.2.1 contained a bug that caused incorrect flagging of backslashes used within triple-quoted strings (e.g., `"""docstring\ncontinuation"""`), leading to false positives.
- gotcha There are known limitations where the plugin might not correctly handle backslashes in specific contexts, such as raw f-strings (e.g., `rf"...\n..."`) or where PEP 8 historically allowed backslashes for `with` statements. This can result in unexpected `N400` errors or missed violations.
Install
-
pip install flake8-broken-line
Imports
- N/A (auto-discovered plugin)
No direct import statement is needed. The plugin is automatically loaded by Flake8 upon installation.
Quickstart
# test_broken_line.py
message = 'This is a long string that \
uses a backslash for line continuation.'
def my_function(arg1, \
arg2): # This backslash is a violation
pass
# To run this example, save the code as 'test_broken_line.py'
# and execute 'flake8 test_broken_line.py' in your terminal.
# You should see an N400 error reported.