Flake8 Commas

4.0.0 · active · verified Thu Apr 16

Flake8 Commas is a plugin for the Flake8 linter that enforces consistent use of trailing commas in Python code. It helps developers avoid annoying merge conflicts when working with multi-line dictionaries, lists, and function calls. The current version is 4.0.0, and as a Flake8 plugin, its release cadence is tied to the broader Flake8 ecosystem.

Common errors

Warnings

Install

Quickstart

After installing flake8-commas, simply run the `flake8` command on your Python files. The plugin will automatically integrate and report comma-related errors, such as missing trailing commas (e.g., C812) or prohibited trailing commas on bare tuples (C818).

print('Checking for comma errors...')
# example.py
def my_function(
    arg1,
    arg2
): # C812: missing trailing comma
    pass

my_list = [
    1,
    2
] # C812: missing trailing comma

my_dict = {
    'key1': 'value1',
    'key2': 'value2'
} # C812: missing trailing comma

# This will trigger C818: trailing comma on bare tuple prohibited
accidental_tuple = 'item1', 'item2', 

# To run flake8-commas:
# 1. Save the above code to a file named 'example.py'
# 2. Run from your terminal:
#    flake8 example.py

view raw JSON →