Skip to main content

Static checks for common Python code risks and hygiene issues.

Project description

pycodereview

pycodereview logo

pycodereview Python versions downloads License: MIT CI Codecov Security scan

Static checks for common Python code risks and hygiene issues. Runs on a single file and outputs concise reports in CSV or JSON format.

Why pycodereview?

Most static analysis tools (like pylint, flake8, or ruff) focus on style compliance and lint rules. pycodereview is different. It's built to support human code review with clear, impact-based findings.

It aims to:

  • Group findings by impact (Correctness, Security, Robustness, etc.) instead of rule codes.
  • Bridge readability and auditability.
  • Be lightweight and dependency-free (built on Python’s ast/tokenize).
  • Highlight risky patterns, not just style issues (mutable defaults, unsafe deserialization, misuse of assert, etc.).
  • Provide reports you can share in CSV or JSON for auditing or CI review.

What it checks

  • Error Handling: catch-alls, empty except, exception re-raise quality.
  • Correctness: mutable defaults, misuse of assert, identity vs equality, undefined names, return vs annotation mismatches.
  • Security: eval/exec, unsafe subprocess/os.system, unsafe YAML/Pickle.
  • Resource Management: missing context managers, mode/encoding mismatches.
  • Maintainability & Style: wildcard imports, shadowing builtins, naming conventions, missing docstrings (for public API), non-Pythonic loops, len(...) comparisons.
  • Process: TODO/FIXME markers.

Installation

pip install pycodereview

For local development and testing:

pip install -r requirements-dev.txt

Quick Start

Run analysis on a file:

pycodereview path/to/file.py

Write CSV report:

pycodereview path/to/file.py --out review_report.csv

Generate JSON output:

pycodereview path/to/file.py --json-output review.json

Example JSON output:

[
  {
    "file": ".\tests\data\sample_cases.py",
    "category": "Correctness",
    "priority": "HIGH",
    "impacted_lines": "65",
    "potential_impact": "Shared mutable state across calls; surprising behavior.",
    "description": "sample_cases.py: Mutable default in function \"bad_defaults_a\"."
  },
  {
    "file": ".\tests\data\sample_cases.py",
    "category": "Correctness",
    "priority": "HIGH",
    "impacted_lines": "70",
    "potential_impact": "Shared mutable state across calls; surprising behavior.",
    "description": "sample_cases.py: Mutable default in function \"bad_defaults_b\"."
  }
]

Output Formats

CSV

Columns:

  1. Category
  2. Priority
  3. Impacted lines
  4. Potential impact
  5. Description

JSON

Each finding is a JSON object with keys:

  • file
  • category
  • priority
  • impacted_lines
  • potential_impact
  • description

Example CLI options

pycodereview FILE [options]

Options:
  --out OUT            Output CSV path. Default: review_report.csv
  --json-output PATH   Write JSON-formatted report.
  --min-priority {LOW,MEDIUM,HIGH}
                       Only report issues at or above this priority.
  --merge-issues       Merge identical issues across multiple lines.
  --max-lines N        Cap the number of lines listed per issue (default: 1200)
  --version            Show version and exit
  -h, --help           Show help message and exit

Example Local Testing

Run all unit tests with coverage:

pip install -r requirements-dev.txt
pytest --cov=src/pycodereview --cov-report=term --cov-report=html

Limitations

  • Static checks are not a replacement for full linters or type checkers (ruff, flake8, mypy).
  • Some security rules are conservative; false positives are possible.
  • Reports only; no auto-fixes.

Contributing

PRs welcome. Please:

  • add unit tests for new rules,
  • keep messages concise and actionable,
  • document new options in the README,
  • run black and ruff before committing.

License

MIT License. See LICENSE for details.

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

pycodereview-1.0.1.tar.gz (23.9 kB view details)

Uploaded Source

Built Distribution

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

pycodereview-1.0.1-py3-none-any.whl (21.8 kB view details)

Uploaded Python 3

File details

Details for the file pycodereview-1.0.1.tar.gz.

File metadata

  • Download URL: pycodereview-1.0.1.tar.gz
  • Upload date:
  • Size: 23.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.0

File hashes

Hashes for pycodereview-1.0.1.tar.gz
Algorithm Hash digest
SHA256 63250eaa5a450c5757d80305b809fba72563a65a5ea7f5cbe3fee622e1b530d6
MD5 a814ca5860152487a53e00664002c8c9
BLAKE2b-256 081a9c625c8bc94154cf68cfc87e0b69cddd904cbf4d20a8376a723e2edc1461

See more details on using hashes here.

File details

Details for the file pycodereview-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: pycodereview-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 21.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.0

File hashes

Hashes for pycodereview-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f22fe891240242d5823bb2fb5043c755bf9996df60c07eb344e4542c3349ee42
MD5 e2ffebc1e07b6108287f9c087325a750
BLAKE2b-256 9493af9e8032a8f349321b6c5f3155e1f716022d29a633b79824b94a4fa102fd

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