Metadata-Version: 2.4
Name: coerce_type
Version: 1.5.0
Summary: A library providing tools to enforce type hints.
Project-URL: Repository, https://github.com/reyemDarnok/coerce_type.git
Project-URL: Issues, https://github.com/reyemDarnok/coerce_type.git
Author-email: Ben Konrad Meyer <ben.k.meyer@gmail.com>
Maintainer-email: Ben Konrad Meyer <ben.k.meyer@gmail.com>
License-Expression: MIT
License-File: LICENSE
Keywords: annotations,typecasting
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Natural Language :: English
Classifier: Natural Language :: German
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Software Development :: Libraries
Requires-Python: >=3.10
Description-Content-Type: text/markdown

# 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

```shell
pip install coerce_type
```

## Usage
There are two main uses of this library:
The `coerce` function and the `TypeCorrecting` class constructor.

### `coerce`
```pycon
>>> from coerce_type import coerce
>>> target_type = int
>>> value = "1"
>>> coerce(value, target_type)
1
```

### `TypeCorrecting`

```pycon
>>>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
```



