Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

lesspython

Find syntactically equivalent Python code fragments by hashing normalized AST subtrees. This means it can spot duplicates even when variable names or literals change, rather than just matching identical lines of text.

Usage

lesspython /path/to/project --min-lines 5

Normalize literals to ignore constant differences:

lesspython /path/to/project --min-lines 5 --normalize-literals

Exclude paths (repeatable):

lesspython /path/to/project -e .venv -e build -e tests

Ignore blocks

Add # lesspython: ignore on its own line at the top level inside a block to exclude that block from duplication detection. For example, to skip a function:

def noisy():
    # lesspython: ignore
    ...

For nested blocks (e.g., an if inside a function), only the statements within that if block are ignored. The enclosing function can still be reported as duplicate if other parts match.

Output

The CLI prints YAML with these top-level keys:

  • python_files: number of Python files scanned
  • errors: parse/encoding errors
  • groups: duplicate fragment groups with occurrences and spans

Development

Install:

pip install -e .[dev]

Run tests:

python -m unittest discover -s tests

About

AST-based Python duplicate code finder

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Contributors

Languages