Skip to main content

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

coerce_type-1.3.1.tar.gz (9.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

coerce_type-1.3.1-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

Details for the file coerce_type-1.3.1.tar.gz.

File metadata

  • Download URL: coerce_type-1.3.1.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

Hashes for coerce_type-1.3.1.tar.gz
Algorithm Hash digest
SHA256 37b592ce9b06565ce640f0b57a849e758ef006ed7c5e455f6667a59cf8337ae9
MD5 2bc2c85934a396bcc9a3a4e4d9318415
BLAKE2b-256 bb5ba4a6c87454049862707826f5f1a9a20c89ba4784669d6b5ec94dd82c8f37

See more details on using hashes here.

Provenance

The following attestation bundles were made for coerce_type-1.3.1.tar.gz:

Publisher: publish.yml on reyemDarnok/coerce_type

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file coerce_type-1.3.1-py3-none-any.whl.

File metadata

  • Download URL: coerce_type-1.3.1-py3-none-any.whl
  • Upload date:
  • Size: 6.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for coerce_type-1.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 db59edb686a6a546f0124442639d78de3ef2ec13cba3c84dcc4dd84721bd4681
MD5 d5681a19314eb96a857ec0dc2e015cf1
BLAKE2b-256 19091c815800719592777338b85a9ce792b7d42739b4c0ea38e9a99965e15f36

See more details on using hashes here.

Provenance

The following attestation bundles were made for coerce_type-1.3.1-py3-none-any.whl:

Publisher: publish.yml on reyemDarnok/coerce_type

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page