|
1 | | -# Welcome to MkDocs |
| 1 | +# Exacting |
2 | 2 |
|
3 | | -For full documentation visit [mkdocs.org](https://www.mkdocs.org). |
| 3 | +> *(adj.) making great demands on one's skill, attention, or other resources.* |
4 | 4 |
|
5 | | -## Commands |
| 5 | +`exacting` is a picky dataclass runtime utility collection, making sure all type annotations are followed. |
6 | 6 |
|
7 | | -* `mkdocs new [dir-name]` - Create a new project. |
8 | | -* `mkdocs serve` - Start the live-reloading docs server. |
9 | | -* `mkdocs build` - Build the documentation site. |
10 | | -* `mkdocs -h` - Print help message and exit. |
| 7 | +Essentially... **THE** go-to option for dataclasses. heh. |
11 | 8 |
|
12 | | -## Project layout |
| 9 | +**🔑 Key features**: |
| 10 | + |
| 11 | +- **100% static typing.** Because I hate nothing too. |
| 12 | +- Up to **10x faster** than [`pydantic`](https://pydantic.dev)! (Them: 60ms, us: 6~9ms) |
| 13 | + |
| 14 | + |
| 15 | + |
| 16 | +<br /> |
| 17 | + |
| 18 | +**🛍️ Get `exacting`**: |
| 19 | + |
| 20 | +=== "pip" |
| 21 | + |
| 22 | + ``` haskell |
| 23 | + pip install -U exacting |
| 24 | + ``` |
| 25 | + |
| 26 | +=== "uv" |
| 27 | + |
| 28 | + ``` haskell |
| 29 | + uv pip install -U exacting |
| 30 | + ``` |
| 31 | + |
| 32 | +=== "git" |
| 33 | + |
| 34 | + ``` shell |
| 35 | + git clone https://github.com/AWeirdDev/exacting |
| 36 | + ``` |
| 37 | + |
| 38 | +**🔥 Define some model**: |
| 39 | + |
| 40 | +=== "Python 3.10+" |
| 41 | + |
| 42 | + ```python |
| 43 | + from exacting import Exact |
| 44 | + |
| 45 | + class Actor(Exact): |
| 46 | + name: str |
| 47 | + portrays: str |
| 48 | + |
| 49 | + class Show(Exact): |
| 50 | + name: str |
| 51 | + description: str | None |
| 52 | + actors: list[Actor] |
| 53 | + ``` |
| 54 | + |
| 55 | +=== "Python <= 3.9" |
| 56 | + |
| 57 | + ```python |
| 58 | + from typing import List, Optional |
| 59 | + from exacting import Exact |
| 60 | + |
| 61 | + class Actor(Exact): |
| 62 | + name: str |
| 63 | + portrays: str |
| 64 | + |
| 65 | + class Show(Exact): |
| 66 | + name: str |
| 67 | + description: Optional[str] |
| 68 | + actors: List[Actor] |
| 69 | + ``` |
| 70 | + |
| 71 | +**📦 Build 'em**: |
| 72 | + |
| 73 | +```python |
| 74 | +# (1) ✅ OK, exacting is happi |
| 75 | +Show( |
| 76 | + name="Severance", |
| 77 | + description="great show", |
| 78 | + actors=[ |
| 79 | + Actor(name="Adam Scott", portrays="Mark S."), |
| 80 | + Actor(name="Britt Lower", portrays="Helly R."), |
| 81 | + ] |
| 82 | +) |
| 83 | + |
| 84 | +# (2) ❌ Nuh-uh, exacting is angri |
| 85 | +Show( |
| 86 | + name=123, |
| 87 | + description=False, |
| 88 | + actors=[ |
| 89 | + "Walter White", |
| 90 | + "Jesse Pinkman" |
| 91 | + ] |
| 92 | +) |
| 93 | +``` |
| 94 | + |
| 95 | +??? failure "TypeError: Error while validating…" |
| 96 | + |
| 97 | + ``` python |
| 98 | + TypeError: |
| 99 | + Error while validating dataclass 'Show' at attribute 'name': |
| 100 | + (isinstance) Expected <class 'str'>, got: <class 'int'> |
| 101 | + ``` |
| 102 | + |
| 103 | +Normally, when you use the parameters passed in example (2) above, the Python `dataclasses` library might as well just go with it, because they only put the additional **static typing** to the model, but not at **runtime**. Exacting makes sure that at both times, types are all enforced. It even gives you a detailed error message on where this occurs! (In a cool way) |
| 104 | + |
| 105 | +It's worth noting that error generations are *lazy*, which means once Exacting finds out about a problem, it immediately raises a `TypeError` or `ValueError` (depending on the context) when we're at the high-level scale (say, a dataclass). This saves a lot of computation time if you have a larger model. |
13 | 106 |
|
14 | | - mkdocs.yml # The configuration file. |
15 | | - docs/ |
16 | | - index.md # The documentation homepage. |
17 | | - ... # Other markdown pages, images and other files. |
|
0 commit comments