Status
Compatibilities
Contact
AdTypingDecorators
Python decorators allowing to check and/or enforce types in functions' arguments based on typing hints.
Installation
pip install adtypingdecorators
Usage
import numpy as np
import pandas as pd
from adtypingdecorators import typing_raise, typing_convert, typing_warn, typing_custom
def to_array(a: int):
return np.array([a, 2 * a])
def to_array_2(a: int):
return np.array([a, 3 * a])
@typing_raise
def f_raise(a: int):
return a + 1
@typing_convert
def f_convert(a: int):
return a + 1
@typing_warn
def f_warn(a: int):
return a + 1
@typing_custom(
convertors={int: to_array, "b": to_array_2},
exclude=["c", pd.DataFrame]
)
def f_custom(a: np.ndarray, b: np.ndarray, c: np.ndarray, d: np.ndarray):
return a + 1, b + 1, c + 1, d + 1
f_raise(1) # Returns 2, as expected
# noinspection PyTypeChecker
f_raise(1.5) # Raises TypeError
# noinspection PyTypeChecker
f_convert(1.5) # Returns 2 (converted 1.5 into 1)
# noinspection PyTypeChecker
f_convert("foo") # Raises ValueError (while trying to convert 'foo' to interger)
# noinspection PyTypeChecker
f_warn(1.5) # Returns 2.5, and warns
# noinspection PyTypeChecker
a_, b_, c_, d_ = f_custom(1, 2, 3, pd.DataFrame([4]))
# a_ is np.array([2, 3])
# b_ is np.array([3, 7])
# c_ is 4
# d_ is pd.DataFrame([5])
Metadata
Release files for adtypingdecorators 0.1.26
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| adtypingdecorators-0.1.26.tar.gz | 38.1 kB | Without provenance | Details for adtypingdecorators-0.1.26.tar.gz |
Release files / adtypingdecorators-0.1.26.tar.gz
| Download URL | adtypingdecorators-0.1.26.tar.gz |
|---|---|
| Size | 38.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
444263564ccb413dac0f74e18cdb7b30b0d2e5ef5de3413bdd9fe72e5298c39c
|
|
BLAKE2b-256 checksum How to use checksums |
0bdb0d107bc9748f9bbfe8248b8686929dcc4348556314b9dd4959b79396f464
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.0 CPython/3.9.12
|
Security for adtypingdecorators 0.1.26
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.