{"id":9441,"library":"add-trailing-comma","title":"add-trailing-comma","description":"add-trailing-comma is a Python utility that automatically adds trailing commas to function calls and literal structures (like lists, tuples, dictionaries, sets) to improve diff clarity and make future additions easier. It is currently at version 4.0.0 and is actively maintained, with releases often tied to Python version updates.","status":"active","version":"4.0.0","language":"en","source_language":"en","source_url":"https://github.com/asottile/add-trailing-comma","tags":["formatting","code quality","linter","cli tool","automation"],"install":[{"cmd":"pip install add-trailing-comma","lang":"bash","label":"Install latest version"}],"dependencies":[],"imports":[{"note":"This library is a command-line tool and is not intended for programmatic import or direct use as a Python module.","wrong":"import add_trailing_comma","symbol":"add-trailing-comma (CLI)","correct":"add-trailing-comma <filenames>..."}],"quickstart":{"code":"# Create a Python file, e.g., 'example.py'\n# -- example.py BEFORE --\n# def my_function(arg1, arg2):\n#     pass\n# \n# my_list = [\n#     1,\n#     2\n# ]\n# \n# my_dict = {\n#     'key1': 'value1',\n#     'key2': 'value2'\n# }\n\n# Run the tool from your terminal:\n# $ add-trailing-comma example.py\n\n# -- example.py AFTER --\n# def my_function(arg1, arg2,):\n#     pass\n# \n# my_list = [\n#     1,\n#     2,\n# ]\n# \n# my_dict = {\n#     'key1': 'value1',\n#     'key2': 'value2',\n# }","lang":"python","description":"First, create a Python file with some function calls or literals. Then, run `add-trailing-comma` on that file from your terminal. The tool will modify the file in-place, adding trailing commas where applicable."},"warnings":[{"fix":"Ensure you are running `add-trailing-comma` within a Python 3.10+ environment. If you need to use an older Python environment, you must install an older version of `add-trailing-comma` (e.g., `<4.0.0`).","message":"As of version 4.0.0, the `add-trailing-comma` tool itself now requires Python 3.10 or newer to run. Attempting to install or execute it with older Python versions will result in an error.","severity":"breaking","affected_versions":"4.0.0+"},{"fix":"Remove these flags from your command-line invocations or pre-commit configurations. The tool will now handle the appropriate Python version inference.","message":"The command-line flags `--py36-plus` and `--py310-plus` were removed in version 4.0.0. The tool now automatically infers the target Python version of the code it's formatting based on the Python environment it's running in.","severity":"breaking","affected_versions":"4.0.0+"},{"fix":"Always commit your code before running `add-trailing-comma` or ensure you have a robust backup strategy. Integrate it as part of a pre-commit hook for automated version control management.","message":"`add-trailing-comma` modifies files in-place without creating backups. It is strongly recommended to use this tool within a version-controlled repository (e.g., Git) to easily review and revert any unintended changes.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Configure your pre-commit hooks or formatting scripts to execute `add-trailing-comma` before other formatters that might conflict with trailing comma placement.","message":"When combining `add-trailing-comma` with other code formatters (e.g., Black, Ruff), it should generally be run *before* the other formatters in your pipeline (e.g., pre-commit hooks). Some opinionated formatters might remove trailing commas in certain contexts, potentially undoing `add-trailing-comma`'s work if run out of order.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-17T00:00:00.000Z","next_check":"2026-07-16T00:00:00.000Z","problems":[{"fix":"Run the tool directly from your terminal using `add-trailing-comma <files>` or `python -m add_trailing_comma <files>`.","cause":"This library is a command-line utility and is not designed for programmatic 'import' into Python scripts.","error":"ModuleNotFoundError: No module named 'add_trailing_comma'"},{"fix":"Ensure the package is installed (`pip install add-trailing-comma`) and your Python environment's script directory is in your PATH. If using a virtual environment, make sure it's activated. Alternatively, run via `python -m add_trailing_comma <files>`.","cause":"The `add-trailing-comma` executable is not in your system's PATH, or the package was not successfully installed.","error":"add-trailing-comma: command not found"},{"fix":"Switch to a Python 3.10 or newer environment. If you absolutely need to use an older Python environment, you must install an older version of `add-trailing-comma` (e.g., `pip install 'add-trailing-comma<4.0.0'`) that is compatible with your Python version.","cause":"You are attempting to install or run `add-trailing-comma` version 4.0.0+ with a Python interpreter older than 3.10.","error":"ERROR: add-trailing-comma requires Python '>=3.10' but the running Python is X.Y"}]}