Skip to content

FrenchCommando/trailing-comma

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

trailing-comma

PyPI

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.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages