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.
Release files for typeduck 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| typeduck-0.1.0.tar.gz | 3.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| typeduck-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 7.6 kB
Release files / typeduck-0.1.0.tar.gz
| Download URL | typeduck-0.1.0.tar.gz |
|---|---|
| Size | 3.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f8e43678b0b51d2ab1b06f04b10ed8c943010ad370ceedbd7cb983caf85d40c6
|
|
BLAKE2b-256 checksum How to use checksums |
4bde9e41dd5d11c75748c092bf844d53f1bea46d0763404196d9a37e3eaa1732
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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
|
Release files / typeduck-0.1.0-py3-none-any.whl
| Download URL | typeduck-0.1.0-py3-none-any.whl |
|---|---|
| Size | 3.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8a90b8de1358656f6d00254d6ec687e621a54404685f67b52c6821342904c728
|
|
BLAKE2b-256 checksum How to use checksums |
e56b5e024a0182b4dda34932e1edf995f8bbf49a94057edf35f8bf6d7f6b2cf0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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
|