{"id":7231,"library":"flake8-commas","title":"Flake8 Commas","description":"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.","status":"active","version":"4.0.0","language":"en","source_language":"en","source_url":"https://github.com/PyCQA/flake8-commas/","tags":["flake8","linting","code-quality","trailing-commas","python"],"install":[{"cmd":"pip install flake8-commas","lang":"bash","label":"Install latest version"}],"dependencies":[{"reason":"flake8-commas is a plugin for the Flake8 linter and requires Flake8 to function.","package":"flake8"}],"imports":[],"quickstart":{"code":"print('Checking for comma errors...')\n# example.py\ndef my_function(\n    arg1,\n    arg2\n): # C812: missing trailing comma\n    pass\n\nmy_list = [\n    1,\n    2\n] # C812: missing trailing comma\n\nmy_dict = {\n    'key1': 'value1',\n    'key2': 'value2'\n} # C812: missing trailing comma\n\n# This will trigger C818: trailing comma on bare tuple prohibited\naccidental_tuple = 'item1', 'item2', \n\n# To run flake8-commas:\n# 1. Save the above code to a file named 'example.py'\n# 2. Run from your terminal:\n#    flake8 example.py","lang":"python","description":"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)."},"warnings":[{"fix":"pip uninstall flake8-commas-x && pip install flake8-commas","message":"The project was temporarily renamed to `flake8-commas-x` for versions 3.x.x, then renamed back to `flake8-commas` in version 4.0.0. If you are upgrading from `flake8-commas-x`, you *must* uninstall `flake8-commas-x` before installing `flake8-commas` to avoid conflicts.","severity":"breaking","affected_versions":">=3.0.0, <4.0.0 (flake8-commas-x) to 4.0.0 (flake8-commas)"},{"fix":"Ensure your project uses Python 3.8 or newer. Update your `flake8` configuration if you relied on `flake8-commas`'s specific `noqa` handling.","message":"Version 3.0.0 (released as `flake8-commas-x`) dropped support for Python versions older than 3.8 and removed explicit `noqa` handling, as `flake8` now manages this directly.","severity":"breaking","affected_versions":"<3.8 (Python), >=3.0.0 (flake8-commas-x)"},{"fix":"Configure your `.flake8`, `setup.cfg`, or `pyproject.toml` to ignore error codes for Python versions not used in your project (e.g., `ignore = C814,C815,C816` if only targeting Python 3.8+).","message":"Different Python versions have varying requirements and conventions for trailing commas. Flake8 Commas reports specific error codes (e.g., C813 for Python 3, C815 for 3.5+, C816 for 3.6+) based on these differences.","severity":"gotcha","affected_versions":"All"},{"fix":"Evaluate if you prefer a linter (flake8-commas) for reporting issues or an auto-formatter (Black, add-trailing-comma) for automatically fixing them. Both approaches can coexist, but ensure consistency in your tooling.","message":"For a period, `flake8-commas` was unmaintained, with recommendations to use automatic formatters like Black or `add-trailing-comma`. While the project is now actively maintained again (v4.0.0+), automatic formatters offer a different approach to comma enforcement.","severity":"gotcha","affected_versions":"<4.0.0"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Upgrade to `flake8-commas` version 4.0.0 or newer. If `flake8-commas-x` was installed, uninstall it first: `pip uninstall flake8-commas-x && pip install --upgrade flake8-commas`.","cause":"Older versions of `flake8-commas` (pre-4.0.0 / pre-`flake8-commas-x`) were incompatible with Python 3.12 due to changes in Python's AST tokenization.","error":"IndexError: list index out of range (during flake8 execution)"},{"fix":"Remove the trailing comma for bare assignments that are not explicitly intended as tuples, or explicitly enclose the tuple in parentheses if that is the desired type: `value = 1, 2` or `value = (1, 2, 3,)`.","cause":"This error occurs when a trailing comma is used on a 'bare' (unparenthesized) tuple, which can lead to unexpected type interpretation in Python (e.g., `value = 1, 2,` is a tuple).","error":"C818 trailing comma on bare tuple prohibited"},{"fix":"Ensure both `flake8` and `flake8-commas` are installed in the *same* active Python environment. Verify using `pip list` and `flake8 --version`. If previously using `flake8-commas-x`, explicitly uninstall it (`pip uninstall flake8-commas-x`) before reinstalling `flake8-commas` (`pip install --upgrade flake8-commas`).","cause":"The `flake8-commas` package is likely installed in a different Python environment than where `flake8` is being executed, or there's a lingering conflict from the `flake8-commas-x` migration.","error":"Flake8 is not recognizing flake8-commas plugin / Flake8 does not report C8xx errors"}]}