Skip to main content

No project description provided

Project description

typeduck

Introduction

A lightweight utility for comparing annotation declarations for their compatibility.

Installation

Requires Python 3.8 or above.

pip install typeduck

Usage

from typing import Union, List
from typeduck import types_validate

source = List[str]
target = List[Union[str, int]]

types_validate(source, target)  # returns a boolean
# OR
types_validate(source, target, raises=True)  # will raise a TypeError when validation fails

Use Cases

Validate annotations between functions or classes match

from typing import List, Union
from typeduck import types_validate

def my_func() -> List[str]:
    ...

def your_func(data: List[Union[int, str]]):
    ...

source = my_func.__annotations__['return']
target = your_func.__annotations__['data']

are_compatible = types_validate(source, target)  # True

See more examples in the tests.py file.

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

typeduck-0.1.0.tar.gz (3.7 kB view details)

Uploaded Source

Built Distribution

typeduck-0.1.0-py3-none-any.whl (3.9 kB view details)

Uploaded Python 3

File details

Details for the file typeduck-0.1.0.tar.gz.

File metadata

  • Download URL: typeduck-0.1.0.tar.gz
  • Upload date:
  • Size: 3.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.10.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10

File hashes

Hashes for typeduck-0.1.0.tar.gz
Algorithm Hash digest
SHA256 f8e43678b0b51d2ab1b06f04b10ed8c943010ad370ceedbd7cb983caf85d40c6
MD5 1870a8f232c8eb95ef40388a546b3e4f
BLAKE2b-256 4bde9e41dd5d11c75748c092bf844d53f1bea46d0763404196d9a37e3eaa1732

See more details on using hashes here.

File details

Details for the file typeduck-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: typeduck-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 3.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.10.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10

File hashes

Hashes for typeduck-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8a90b8de1358656f6d00254d6ec687e621a54404685f67b52c6821342904c728
MD5 ff7925f193d7e452987ec2a49c536970
BLAKE2b-256 e56b5e024a0182b4dda34932e1edf995f8bbf49a94057edf35f8bf6d7f6b2cf0

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