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.0.tar.gz (23.8 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.0-py3-none-any.whl (21.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pycodereview-1.0.0.tar.gz
  • Upload date:
  • Size: 23.8 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.0.tar.gz
Algorithm Hash digest
SHA256 9e7aa64d4fe55a51d35745b30f113a94248c1190954cff4ca9d1f49e905a7014
MD5 588cdd40828dfb3ded640ed93c75448e
BLAKE2b-256 24281017eba08ac75d286c50315387b086236513ab6ed6ccdc33c27d975012b2

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pycodereview-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 21.7 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 18e8a981784ee36a3ef04f28e645fdfab12a51aee6e2ba678b448478c7ac4a93
MD5 3c898f13e3a91b17b213d25fd56c7d3e
BLAKE2b-256 af664d05d61e420ebbd3ff07b2e92eb61f08a0a8f343c6e3d10d6e5b04ad8b80

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