Skip to main content

Python type annotation existence checker

This project has been archived.

The maintainers of this project have marked this project as archived. No new releases are expected.

Project description

PyLeft

Black pre-commit GitHub license PyPi versions PyPi downloads

Python type annotation existence checker


pyleft is a complement to Microsoft's pyright tool. While pyright does an excellent job at type checking your Python code, it doesn't check to make sure type hints exist. If you forget to add type hints to a function, pyright will usually see no problems with it. This tool checks to make sure all of your code has type hints, while leaving it to pyright to make sure they are actually correct.

Installation

PyLeft requires Python 3.7+.

pip install pyleft

Usage

PyLeft is a Python module that can be run via python -m. Just provide the directories or files to recursively check.

python -m pyleft .

The module will exit with an exit code of 0 if all type hints are present, or 1 if there are any issues.

Example

> pyleft .
- tests/files/fail_1.py
        Argument 'two' of function 'add:1' has no type annotation
- tests/files/fail_2.py
        Function 'add:1' has no return type annotation
- tests/files/fail_3.py
        Function 'drive:2' has no return type annotation
- tests/files/fail_4.py
        Argument 'one' of function 'wheels:4' has no type annotation

Options

  • paths: File and directory names to recursively check.
  • --exclude: (optional) List of pattern(s) of files/directories to exclude in gitignore format. Takes precedence over paths.
  • --no-gitignore: (optional) Don't use the exclusions from the .gitignore file(s) in the current working directory.
  • --ignore-if-has-default: (optional) Ignore a lack of annotation if a function argument has a default value.
  • --quiet: (optional) Don't print any output to STDOUT.
  • --verbose: (optional) Print debugging information to STDERR.

Configuration

Configuration is done through the pyproject.toml file.

[tool.pyleft]
# "paths" in the configuration file are added to the option given on the
# command line
# This can either be a list, or a space separated string
paths = ["extra/directory/"]
# This can either be a list, or a space separated string
exclude = ["*_pb2.py"]
# These are all booleans
no-gitignore = false
ignore-if-has-default = false
quiet = false
verbose = false

Design Decisions

If a .pyi file exists alongside a .py file, only the .pyi file will be checked.

The __init__ and __new__ methods of a class are not required to have return type hints. pyright automatically assumes this to be None.

The first (self) argument of any class method is not required to have a type hint.

The first (cls) argument of any class @property or @classmethod or __new__ method is not required to have a type hint.

Any variable argument list (*arg) or keyword argument dict (**kwarg) is not required to have a type hint.

Types of types, such as List or Tuple are not required. For example, a type hint of just list is allowed, although you should normally be as specific as possible with a better type hint like List[int].

Disclaimer

This project is not affiliated in any way with Microsoft.

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

pyleft-1.2.0.tar.gz (9.3 kB view details)

Uploaded Source

Built Distribution

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

pyleft-1.2.0-py3-none-any.whl (10.2 kB view details)

Uploaded Python 3

File details

Details for the file pyleft-1.2.0.tar.gz.

File metadata

  • Download URL: pyleft-1.2.0.tar.gz
  • Upload date:
  • Size: 9.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.0 CPython/3.10.6 Linux/5.15.0-1037-azure

File hashes

Hashes for pyleft-1.2.0.tar.gz
Algorithm Hash digest
SHA256 dab8d9fd81ba8b683bd63370483dcc32d3e3e83595a63e7c9b738a959f9a5164
MD5 fd4f8374643247ebf00bfac42e2c3815
BLAKE2b-256 a96bf6133e7d87a393956058ae227e00c0292fc467bd5c59342bbe4057c07ce1

See more details on using hashes here.

File details

Details for the file pyleft-1.2.0-py3-none-any.whl.

File metadata

  • Download URL: pyleft-1.2.0-py3-none-any.whl
  • Upload date:
  • Size: 10.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.0 CPython/3.10.6 Linux/5.15.0-1037-azure

File hashes

Hashes for pyleft-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 72a54cc9e80e42074da390b7502cc6e6a0947ea24fe49b1907a5eb0380633584
MD5 d9d01f746785d87cd48eea3639cbb34e
BLAKE2b-256 f73fa4075c57898db9c8c2dbf444fa1fa8f211a6579bda6ad315424475bd8cc3

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