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.2.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.2-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: coerce_type-1.3.2.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.2.tar.gz
Algorithm Hash digest
SHA256 9f9a4f16ba29cb80176be22275555ff8e35c02e287359a4f11d7942def80ddf6
MD5 e96b0614e011e9158c73e82d47a1ba98
BLAKE2b-256 e4fd2c25a8611db4c2bf1f87bcaff6e8e6fa4ae94a58bbcff3900b3c1bb37aee

See more details on using hashes here.

Provenance

The following attestation bundles were made for coerce_type-1.3.2.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.2-py3-none-any.whl.

File metadata

  • Download URL: coerce_type-1.3.2-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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 d40d0d27e0b376a5ba95304b5de9198b5f1269eaeccbf0a72783acdc6198a7ac
MD5 30aaccf711a25b6c5e0534aac3cb2a9b
BLAKE2b-256 14a03e2f3c74b7d6ce9f415f1ad20e59f3fe765845ddaff678de5464e942f71e

See more details on using hashes here.

Provenance

The following attestation bundles were made for coerce_type-1.3.2-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