Skip to content

Commit ee7319b

Browse files
committed
hell nawh
1 parent 594949d commit ee7319b

4 files changed

Lines changed: 13 additions & 18 deletions

File tree

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
> *(adj.) making great demands on one's skill, attention, or other resources.*
44
5+
[**Docs**](https://aweirddev.github.io/exacting) and [**PyPi**](https://pypi.org/project/exacting)
6+
57
`exacting` is a picky dataclass runtime utility collection, making sure all type annotations are followed.
68

79
Essentially... **THE** go-to option for dataclasses. heh.
@@ -146,4 +148,4 @@ Woah! That's a lot of code to process. To put it simply, exacting supports:
146148

147149
Kind of, but somehow native performance is way better than Rust. That is, exacting is *generally* faster than Pydantic on a few benchmarks. Woooosh
148150

149-
Anyway, thanks for hopping onto this quick tour, you can [read the docs](https://aweirddev.github.io/exacting) if you'd like.
151+
Anyway, thanks for sticking with us, you can [read the docs](https://aweirddev.github.io/exacting) if you'd like.

docs/index.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Essentially... **THE** go-to option for dataclasses. heh.
99
**🔑 Key features**:
1010

1111
- **100% static typing.** Because I hate nothing too.
12-
- Up to **10x faster** than [`pydantic`](https://pydantic.dev)! (Them: 60ms, us: 6~9ms)
12+
- Generally **faster** than [`pydantic`](https://pydantic.dev)!
1313

1414
![static typing](static-typing-proof.png)
1515

@@ -95,11 +95,12 @@ Show(
9595
??? failure "TypeError: Error while validating…"
9696

9797
``` python
98-
TypeError:
99-
Error while validating dataclass 'Show' at attribute 'name':
100-
(isinstance) Expected <class 'str'>, got: <class 'int'>
98+
ValidationError:
99+
During validation of dataclass Show at field 'name', got:
100+
Expected type <class 'str'>, got <class 'int'>
101101
```
102102

103103
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)
104104

105105
It's worth noting that error generations are *lazy*, which means once Exacting finds out about a problem about a dataclass, it raises a `ValidationError`. This saves a lot of computation time if you have a larger model.
106+

python/exacting/core.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,15 +87,14 @@ class _Dc: ...
8787

8888
class _Dc: ...
8989

90-
class _Internals: ...
90+
class _Internals:
91+
def __init__(self, **kwargs):
92+
get_exact_init(self)(self, **kwargs)
9193

9294

9395
class Exact(_Dc, _Internals):
9496
"""Represents a dataclass with runtime type checks."""
9597

96-
def __init__(self, **kwargs):
97-
get_exact_init(self)(self, **kwargs)
98-
9998
def __init_subclass__(cls):
10099
dataclass(cls)
101100

test.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,15 @@ class Show(Exact):
1111
description: str | None
1212
actors: list[Actor]
1313

14+
1415
# (1) ✅ OK, exacting is happi
1516
Show(
1617
name="Severance",
1718
description="great show",
1819
actors=[
1920
Actor(name="Adam Scott", portrays="Mark S."),
2021
Actor(name="Britt Lower", portrays="Helly R."),
21-
]
22+
],
2223
)
2324

2425
# (2) ❌ Nuh-uh, exacting is angri
25-
Show(
26-
name=123,
27-
description=False,
28-
actors=[
29-
"Walter White",
30-
"Jesse Pinkman"
31-
]
32-
)

0 commit comments

Comments
 (0)