Skip to main content

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 .py files 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

check_duplicate_variables-1.0.5.tar.gz (12.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

check_duplicate_variables-1.0.5-py3-none-any.whl (9.2 kB view details)

Uploaded Python 3

File details

Details for the file check_duplicate_variables-1.0.5.tar.gz.

File metadata

File hashes

Hashes for check_duplicate_variables-1.0.5.tar.gz
Algorithm Hash digest
SHA256 e7d416face45f9b4b3ae57014f296013462a265c3e7377763d74ad4b792e062c
MD5 5894e041a96af2740ce1609937998b0a
BLAKE2b-256 b616868e19787221ddd6aac02eb28d21125e60844731772076cef05867cb1419

See more details on using hashes here.

File details

Details for the file check_duplicate_variables-1.0.5-py3-none-any.whl.

File metadata

File hashes

Hashes for check_duplicate_variables-1.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 f11349c42629be478526e4cad066ac0ef101056ec948e2164bd1d9891330e38f
MD5 a27017888a8df61f223cffb84c63a8a7
BLAKE2b-256 356dea0f6415fae246eceae7bfd2fb92becea4731be22b193dea8aeb96d4c275

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page