trailing-comma
Add and remove trailing commas in Python source files.
A minimal replacement for add-trailing-comma, built on tokenize-rt. No AST — walks the token stream directly.
The original only exposes file and stdin interfaces — no way to work on strings directly.
Exposing fix_trailing_commas(source) as the core API makes it usable as a library and
directly testable, which revealed a latent bug in the original's unhug re-indentation logic.
Install
pip install trailing-comma
For development (includes build and twine for publishing):
pip install -e ".[dev]"
Usage
Rewrite files in place:
trailing-comma file1.py file2.py
From stdin (no arguments):
echo "foo(
a, b
)" | trailing-comma
As a library:
from trailing_comma import fix_trailing_commas
result = fix_trailing_commas(source)
What it does
- Adds trailing commas to multi-line calls, defs, imports, lists, dicts, sets, and tuples
- Removes trailing commas from single-line constructs (preserves single-element tuples)
- Unhugs content from braces and fixes closing brace indentation
What it skips
Generators, comprehensions, class bases, subscripts, parenthesized expressions.
Metadata
Release files for trailing-comma 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| trailing_comma-0.1.1.tar.gz | 10.2 kB | Without provenance | Details for trailing_comma-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| trailing_comma-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for trailing_comma-0.1.1-py3-none-any.whl |
Total release size: 17.2 kB
Release files / trailing_comma-0.1.1.tar.gz
| Download URL | trailing_comma-0.1.1.tar.gz |
|---|---|
| Size | 10.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
05b4780b1247bb5bf1dd7cddef14d2b402b0041751362c63d8fd002f705e0092
|
|
BLAKE2b-256 checksum How to use checksums |
edd6a28643cc43183d06f1991b3b732ea8fce4cb3854b8f44a75799c7d0bdebb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.0rc3
|
Release files / trailing_comma-0.1.1-py3-none-any.whl
| Download URL | trailing_comma-0.1.1-py3-none-any.whl |
|---|---|
| Size | 7.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
eb5036d592821e7efa97b2e8b995c48a54eae9840aeff870ff7d34884cc21f33
|
|
BLAKE2b-256 checksum How to use checksums |
98ccfd0329f53ab33e86b6637498f2b5bffdcf5328498449c22133b06df4dfab
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.0rc3
|
Security for trailing-comma 0.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.