Flake8 Quotes
flake8-quotes is a Flake8 extension that lints Python code for consistent quote usage. It helps enforce a preferred quote style (single or double) for inline strings, multiline strings, and docstrings, and by default, encourages avoiding escaped quotes as per PEP 8. The current version is 3.4.0, with releases occurring periodically, the latest being in February 2024, indicating active maintenance.
Warnings
- deprecated The `--quotes` CLI option and `quotes` configuration setting were renamed to `--inline-quotes` and `inline-quotes` respectively in version 0.3.0.
- breaking In version 2.0.0, the default behavior changed to automatically encourage avoiding escaping quotes as per PEP 8. This means `avoid-escape` is now `True` by default.
- gotcha Installing flake8-quotes does not automatically enable its checks. You must explicitly include the 'Q0' prefix in your Flake8 `select` configuration.
- gotcha When configuring flake8-quotes within `pyproject.toml` (especially with tools like `flakeheaven`), string values for options like `inline-quotes` must be explicitly quoted, e.g., `inline-quotes = "double"`.
Install
-
pip install flake8-quotes
Imports
- No direct import
This is a flake8 plugin and is not imported directly in Python code.
Quickstart
# 1. Create a Python file, e.g., 'bad_quotes.py' # bad_quotes.py message = 'Hello, world!' # Intended to be flagged if double quotes are preferred """This is a docstring.""" # Intended to be flagged if single quotes are preferred # 2. Create a configuration file, e.g., 'pyproject.toml' or '.flake8' # pyproject.toml # [tool.flake8] # inline-quotes = "double" # multiline-quotes = "single" # docstring-quotes = "single" # select = ["E", "F", "W", "Q0"] # avoid-escape = true # This is the default behavior # .flake8 (alternative to pyproject.toml) # [flake8] # inline-quotes = double # multiline-quotes = single # docstring-quotes = single # select = E,F,W,Q0 # avoid-escape = True # 3. Run flake8 from your terminal in the same directory # flake8 bad_quotes.py # Expected output (example, may vary based on exact config and content): # bad_quotes.py:3:11: Q000 Remove bad quotes # bad_quotes.py:5:1: Q002 Remove bad quotes from docstring