Takes
Decorator for run-time type checks.
Free software: MIT license
Documentation: https://takes.readthedocs.io.
Features
Convert undefined dictionaries accepted by functions to strong data types, without changing calling code.
Decorated functions can be called with dictionaries as before, or with instances of the desired type.
Example
This function takes an undocumented dictionary. Maintainers must read the function body to determine the expected shape of the data.
def my_function(data):
x, y = data["x"], data["y"]
return f"x={x}, y={y}"
>>> my_function({"x": 1, "y": 1})
"x=1, y=1"
Takes lets you redefine this function to accept a well-defined data type, without needing to immediately change all of the calling code:
from takes import takes
@dataclass
class Point:
x: int
y: int
@takes(Point)
def my_function(point):
x, y = point.x, point.y
return f"x={x}, y={y}"
# Can still call my_function with a dictionary,
# Takes will convert it to a point by instantiating
# a Point using the given data as kwargs:
>>> my_function({"x": 1, "y": 1})
"x=1, y=1"
# Of course, you can also call the function with the proper
# type:
>>> my_function(Point(x=1, y=1))
"x=1, y=1"
Further, takes performs type checks at run-time.
Credits
This package was created with Cookiecutter and the pymetrics/cookiecutter-python-library project template.
History
0.2.0 (2021-11-28)
First release on PyPI.
Metadata
Release files for takes 0.2.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 | Provenance | Actions |
|---|---|---|---|---|
| takes-0.2.0.tar.gz | 13.4 kB | Without provenance | Details for takes-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| takes-0.2.0-py2.py3-none-any.whl | Python 2, Python 3 | none | any | Details for takes-0.2.0-py2.py3-none-any.whl |
Total release size: 17.5 kB
Release files / takes-0.2.0.tar.gz
| Download URL | takes-0.2.0.tar.gz |
|---|---|
| Size | 13.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2d4b7b49699ee6ad125c418c5032ef05487ada49582926ba58fa60b5a49914e5
|
|
BLAKE2b-256 checksum How to use checksums |
3d153898af4e1a3d54f17f249c9f16695a3e47488ab0813b7586cce06a6c123c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.2 importlib_metadata/4.8.2 pkginfo/1.8.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.9
|
Release files / takes-0.2.0-py2.py3-none-any.whl
| Download URL | takes-0.2.0-py2.py3-none-any.whl |
|---|---|
| Size | 4.2 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
c028447c0c27e93580c71bc28fa34afd5722d0195b707877e9e9ee45304ede4b
|
|
BLAKE2b-256 checksum How to use checksums |
d2c84eb3ce30d72d7f28b2b4a061d7b036f74b4034073ea33759ead76ed48ddf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.2 importlib_metadata/4.8.2 pkginfo/1.8.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.9
|
Security for takes 0.2.0
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.