Skip to main content

A tool to measure the percentage of typed arguments in python functions

Project description

PyTypeGauge

PyTypeGauge is a Python library that provides comprehensive statistics and metrics for your typed functions and Python code. The primary goal is to encourage developers to achieve 100% type coverage in their codebases.

⚠️ Note: PyTypeGauge is a simple tool designed to encourage better type annotation in your Python code. It does not validate the correctness of the types you add. The concept is straightforward: it recursively scans all Python files in a repository, using regular expressions to identify function prototypes and check whether their arguments and return types are annotated. PyTypeGauge then calculates the proportion of fully typed functions and arguments, providing a summary of your type coverage. Additionally, you can generate a comprehensive report in markdown format, highlighting functions and files that may need refactoring or additional type annotations.

PyTypeGauge is intended to be used with pre-commit hooks and can update your README.md with your project's type coverage progress.

Example Output (current type coverage)

typo_progress

For more advanced type checking and validation, consider using other well-maintained libraries such as mypy or pyright.


Features

  • Analyze the type coverage of your Python functions.
  • Generate detailed reports on the use of type hints.
  • Track the progress of type hint adoption in your codebase.

Installation

To install PyTypeGauge, run:

pip install pytypegauge

How to Use typegauge

typegauge is a command-line tool designed to analyze the type annotations in your Python code. You can specify a directory or a Python file, and the tool will evaluate the type coverage of your code. Below is a guide on how to use typegauge and the various options available.

Basic Usage

To analyze a specific directory or Python file, simply run:

typegauge <input>

Replace <input> with the path to the directory or Python file you want to analyze.

Options

  • -h, --help: Show the help message and exit.

    typegauge -h
    
  • -g, --git: Analyze only files tracked by git. This is useful if you want to exclude untracked or ignored files.

    typegauge -g <input>
    
  • -p, --plot-output: Display a graph showing the distribution of typing coverage in your code.

    typegauge -p <input>
    
  • -csv CSV_OUTPUT, --csv-output CSV_OUTPUT: Save the results to a CSV file. Provide the desired CSV file name.

    typegauge -csv results.csv <input>
    
  • -md, --markdown-output: Output the results in a markdown format suitable for inclusion in a README.md on GitHub. This is useful for creating progress badges or reports in your repository.

    typegauge -md <input>
    
  • -c, --clean-output: Only return the percentage of typed arguments, which is useful for scripts and continuous integration setups.

    typegauge -c <input>
    
  • -f, --full-report: Generate a full report listing all functions that are not fully typed. This can help you identify areas in your code that need improvement.

    typegauge -f <input>
    

By using these options, you can tailor the output of typegauge to suit your needs, whether you want a quick summary, a detailed report, or integration with other tools.

TODO:

  • Add hooks for pre-commit
  • Add a description of the project
  • Add a list of the project's dependencies in setup.py
  • Fix bugs in the project
  • Add a Logger to the project for Debugging
  • Type correctly the project
  • Add the feature with matplotlib
  • Translate the code in English
  • Add the feature with pandas
  • add tests for the project
  • Clean the code
  • Add to pypi
  • Make the readme more informative
  • Create the hooks to use this project as a template
  • Add the feature to generate a badge
  • Add verbose mode

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

pytypegauge-0.2.tar.gz (10.5 kB view details)

Uploaded Source

Built Distribution

pytypegauge-0.2-py3-none-any.whl (10.0 kB view details)

Uploaded Python 3

File details

Details for the file pytypegauge-0.2.tar.gz.

File metadata

  • Download URL: pytypegauge-0.2.tar.gz
  • Upload date:
  • Size: 10.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.5

File hashes

Hashes for pytypegauge-0.2.tar.gz
Algorithm Hash digest
SHA256 0825814db9358c1dc6e4e89d79ec19beb19c120c5e4b1507387e3b6cf3dcb539
MD5 e04af2c35b80bcedd3e2c121c7b2b154
BLAKE2b-256 ed3d15348dd81fd3c9042d0bbf80a2e2110549ff360050a7731d79c52eb5d403

See more details on using hashes here.

File details

Details for the file pytypegauge-0.2-py3-none-any.whl.

File metadata

  • Download URL: pytypegauge-0.2-py3-none-any.whl
  • Upload date:
  • Size: 10.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.5

File hashes

Hashes for pytypegauge-0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 15d0876b88a9887f5152f61577b3cc672585165f479c3615950945458b623e86
MD5 23781f7fb3c94727fae979220b277207
BLAKE2b-256 d258b197f441bf67002aa41b77e7444ac2fdd062557a04cc81436813ffe081bf

See more details on using hashes here.

Supported by

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