Detect duplicate variable names within the same scope in Python files
Project description
check-duplicate-variables
A Python tool that detects duplicate variable names within the same scope (module or class) in Python files. Useful for finding copy-paste errors, refactoring issues, and keeping code quality in check (e.g. in page object models).
Features
- AST-based analysis – Uses Python’s AST for accurate parsing
- Scope-aware – Detects duplicates at module and class scope
- Value comparison – Reports whether duplicate assignments have the same or different values
- Multiple assignment types – Handles normal assignments, type-annotated assignments, tuple unpacking, and attribute assignments
- Recursive scanning – Scans all
.pyfiles under a directory - CI-friendly – Exit codes and formatted output for pipelines
Installation
pip install check-duplicate-variables
Requirements: Python 3.8+
Usage
Default (scans a pageobjects directory in the current directory):
check-duplicate-variables
Custom path:
check-duplicate-variables /path/to/your/python/files
As a module:
python -m check-duplicate-variables [directory]
# or
python -m check-duplicate-variables [filepath]
Exit codes: 0 – no duplicates / no errors; 1 – duplicates found or errors.
Output
One line per duplicate:
file_path: variable_name (same values) - line1, line2, line3
file_path: variable_name (different values) - line1, line2
- (same values) – All assignments have the same value (possible copy-paste)
- (different values) – Assignments differ (reassignment or possible bug)
License
MIT – see LICENSE.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file check_duplicate_variables-1.0.5.tar.gz.
File metadata
- Download URL: check_duplicate_variables-1.0.5.tar.gz
- Upload date:
- Size: 12.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e7d416face45f9b4b3ae57014f296013462a265c3e7377763d74ad4b792e062c
|
|
| MD5 |
5894e041a96af2740ce1609937998b0a
|
|
| BLAKE2b-256 |
b616868e19787221ddd6aac02eb28d21125e60844731772076cef05867cb1419
|
File details
Details for the file check_duplicate_variables-1.0.5-py3-none-any.whl.
File metadata
- Download URL: check_duplicate_variables-1.0.5-py3-none-any.whl
- Upload date:
- Size: 9.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f11349c42629be478526e4cad066ac0ef101056ec948e2164bd1d9891330e38f
|
|
| MD5 |
a27017888a8df61f223cffb84c63a8a7
|
|
| BLAKE2b-256 |
356dea0f6415fae246eceae7bfd2fb92becea4731be22b193dea8aeb96d4c275
|