flake8-no-implicit-concat
flake8-no-implicit-concat is a Flake8 plugin designed to forbid implicit string and bytes literal concatenations in Python code. It helps enforce a coding style where string concatenation is always explicit, thereby preventing subtle bugs caused by accidentally concatenated literals. The current version is 0.3.7, and the project maintains an active release cadence with regular updates.
Warnings
- gotcha Implicit string concatenation can lead to silent and hard-to-debug errors, especially when defining lists or tuples where a missing comma can result in two intended separate string elements becoming a single concatenated string. This plugin helps prevent such issues.
- gotcha By default, `flake8-no-implicit-concat` only checks for implicit concatenations on the same line (NIC001). To also check for concatenations spanning multiple lines, you need to enable the `--check-str-concat-over-line-jumps=y` option.
- gotcha This plugin specifically *forbids* implicit string concatenation. Be aware that another popular plugin, `flake8-implicit-str-concat`, has different goals and may *encourage* implicit concatenation in certain multi-line scenarios (e.g., within parentheses for PEP 8 compliance). Choose the plugin that aligns with your desired coding style.
Install
-
pip install flake8-no-implicit-concat
Quickstart
# Install the plugin
pip install flake8-no-implicit-concat
# Create a Python file with implicit concatenation (e.g., example.py)
# print('hello' 'world')
# Run flake8 to detect the issue
flake8 example.py
# Output will include a 'NIC' error, e.g.:
# example.py:1:7: NIC001 Implicit string literal concatenation.