Flake8 Quotes

3.4.0 · active · verified Sat Apr 11

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

Install

Imports

Quickstart

After installing flake8-quotes, you need to configure Flake8 to enable its checks and specify your preferred quote styles. This is typically done in a `pyproject.toml` file (recommended), `.flake8` file, or `setup.cfg`.

# 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

view raw JSON →