A library providing tools to enforce type hints.
Project description
coerce_type
coerce_type is a library for the type coercion of values
to the annotations they have. It can be triggered manually with coerce
or be set to happen automatically for a dataclass by having it inherit a TypeCorrecting class
Installation
pip install coerce_type
Usage
There are two main uses of this library:
The coerce function and the TypeCorrecting class constructor.
coerce
>>> from coerce_type import coerce
>>> target_type = int
>>> value = "1"
>>> coerce(value, target_type)
1
TypeCorrecting
>>>import datetime from coerce_type import TypeCorrecting, TypeCorrectingType
>>> from dataclasses import dataclass
>>> from datetime import date
>>> @dataclass()
>>> class Example(TypeCorrecting()):
>>> a: int
>>> b: datetime.date
>>> data = {
>>> "a": "1",
>>> "b": "2022-01-01"
>>> }
>>> example = Example(**data)
>>> example.a
1
>>> example.b
datetime.date(2022, 1, 1)
>>> isinstance(example, TypeCorrectingType)
True
>>> issubclass(Example,TypeCorrectingType)
True
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file coerce_type-1.3.0.tar.gz.
File metadata
- Download URL: coerce_type-1.3.0.tar.gz
- Upload date:
- Size: 9.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
97d82b6a1d5748bacf5e36f7459854ef593fe1451396ec4d85e22faaf027412b
|
|
| MD5 |
c06f9db951ac3ef266f6920ead7ad1fe
|
|
| BLAKE2b-256 |
0d1e19dc0971fb2c050d8010ba6eca6260e594c222bd5edc99ac6cca954dd416
|
Provenance
The following attestation bundles were made for coerce_type-1.3.0.tar.gz:
Publisher:
publish.yml on reyemDarnok/coerce_type
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
coerce_type-1.3.0.tar.gz -
Subject digest:
97d82b6a1d5748bacf5e36f7459854ef593fe1451396ec4d85e22faaf027412b - Sigstore transparency entry: 1122277764
- Sigstore integration time:
-
Permalink:
reyemDarnok/coerce_type@2926d4955dafa13233cc1ff686ff492728b3e58d -
Branch / Tag:
refs/tags/v1.3.0 - Owner: https://github.com/reyemDarnok
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@2926d4955dafa13233cc1ff686ff492728b3e58d -
Trigger Event:
push
-
Statement type:
File details
Details for the file coerce_type-1.3.0-py3-none-any.whl.
File metadata
- Download URL: coerce_type-1.3.0-py3-none-any.whl
- Upload date:
- Size: 6.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
df549aa502e9be224b57874ce9fd00cc1c9467d71f66a9ff6d42033791c0872f
|
|
| MD5 |
c6b6a05be9f2ab76538925dc3d924ee5
|
|
| BLAKE2b-256 |
15e6a5f978e8344318c301cf9398f47f6f6fb9082329b21d7cce631a1b5eb087
|
Provenance
The following attestation bundles were made for coerce_type-1.3.0-py3-none-any.whl:
Publisher:
publish.yml on reyemDarnok/coerce_type
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
coerce_type-1.3.0-py3-none-any.whl -
Subject digest:
df549aa502e9be224b57874ce9fd00cc1c9467d71f66a9ff6d42033791c0872f - Sigstore transparency entry: 1122277767
- Sigstore integration time:
-
Permalink:
reyemDarnok/coerce_type@2926d4955dafa13233cc1ff686ff492728b3e58d -
Branch / Tag:
refs/tags/v1.3.0 - Owner: https://github.com/reyemDarnok
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@2926d4955dafa13233cc1ff686ff492728b3e58d -
Trigger Event:
push
-
Statement type: