Skip to content

Commit 983ef5b

Browse files
committed
attempting
1 parent ee7319b commit 983ef5b

22 files changed

Lines changed: 400 additions & 132 deletions

docs/dumping.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ print(data) # Money(swag=True)
3737

3838
Exacting uses [rkyv](https://docs.rs/rkyv/latest/rkyv/) for serialization/deserialization.
3939

40+
!!! warning "Lazy developer warning"
41+
42+
This thingy is experimental. It's not yet ready for production, y'know.
43+
4044
```python
4145
from exacting import Exact
4246

docs/fields.md

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -48,34 +48,12 @@ Hamburger(name="WHOPPER")
4848
Hamburger(name="bigmac")
4949
```
5050

51-
52-
??? failure "TypeError: Error while validating…"
53-
54-
```
55-
TypeError:
56-
Error while validating dataclass 'Hamburger' at attribute 'name' (field validator):
57-
Failed to validate Regex on str (doesn't match)
58-
```
59-
6051
Note that the `regex` parameter won't work (skipped) if used on field types that aren't `str`.
6152

6253
## Aliases
6354

6455
Aliases are only used when serializing/deserializing.
6556

66-
```python
67-
from exacting import Exact, field
68-
69-
class Person(Exact):
70-
name: str
71-
description: str = field(alias="desc")
57+
!!! warning
7258

73-
# serializing
74-
person = Person(name="Me", description="broke af")
75-
data = person.exact_as_json()
76-
print(data) # {"name": "Me", "desc": "broke af"}
77-
78-
# deserializing
79-
person2 = Person.exact_from_json(data)
80-
print(person2) # Person(name='Me', description='broke af')
81-
```
59+
We're still working on it... stay tuned, I guess.

docs/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ Show(
9292
)
9393
```
9494

95-
??? failure "TypeError: Error while validating…"
95+
??? failure "ValidationError: During validation of…"
9696

9797
``` python
9898
ValidationError:

docs/internals/result.md

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
# Result
2+
3+
The `Result` class indicates the success/failure of validation.
4+
5+
```python
6+
from exacting import Result
7+
8+
# Success
9+
Result.Ok("some value")
10+
11+
# Error
12+
Result.Err(
13+
"You bad",
14+
"literally"
15+
)
16+
```
17+
18+
## Is OK?
19+
20+
This checks if the validation result is OK.
21+
22+
```python
23+
if some_result.is_ok():
24+
... # good!
25+
else:
26+
... # bad!
27+
```
28+
29+
## Raising
30+
31+
`Result` can help you raise a `ValidationError` if errors are present.
32+
33+
```python
34+
some_result.raise_for_err()
35+
```
36+
37+
## Unwrapping
38+
39+
You can get the data that got through the validation by unwrapping, or the error messages.
40+
41+
```python
42+
ok = Result.Ok(-123)
43+
print(ok.unwrap()) # -123
44+
45+
err = Result.Err("be be nos")
46+
print(err.unwrap_err()) # deque(['be be nos'])
47+
```
48+
49+
## Trace
50+
51+
You can trace errors down using the `trace()` function, making previous errors appear indented.
52+
53+
```python
54+
base_err = Result.Err("Gustavo Fring")
55+
56+
(
57+
base_err
58+
.trace("Woah, there's a gustavo down here")
59+
.trace("Breaking bad!")
60+
.raise_for_err()
61+
)
62+
```
63+
64+
??? failure "ValidationError: Breaking bad!"
65+
66+
```
67+
ValidationError:
68+
Breaking bad!
69+
• Woah, there's a gustavo down here
70+
• Gustavo Fring
71+
```
72+
73+
## Trace below
74+
75+
Make other errors appear indented below your message.
76+
77+
```python
78+
error1 = Result.Err("ooga", "booga")
79+
error2 = Result.trace_below(
80+
"Check these out:",
81+
*error1.unwrap_err()
82+
)
83+
84+
error2.raise_for_err()
85+
```
86+
87+
??? failure "ValidationError: Check these out:"
88+
89+
```
90+
ValidationError:
91+
Check these out:
92+
• ooga
93+
• booga
94+
```

docs/internals/unsafe.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Unsafe
2+
3+
If you take a closer look at a model inherited from the `Exact` model, there's a `__unsafe_init__()` function which allows you to skip all type checks.
4+
5+
However, if directly called, you'd get an error:
6+
7+
```python
8+
from exacting import Exact
9+
10+
class Person(Exact):
11+
name: str
12+
13+
Person.__unsafe_init__(name="Walter")
14+
```
15+
16+
??? failure "RuntimeError: Scope is not in unsafe()…"
17+
18+
```python
19+
RuntimeError: Scope is not in unsafe(), canceled operation
20+
```

docs/type-reference/annotated.md

Lines changed: 0 additions & 14 deletions
This file was deleted.

docs/type-reference/any.md

Lines changed: 0 additions & 10 deletions
This file was deleted.

docs/type-reference/literal.md

Lines changed: 0 additions & 13 deletions
This file was deleted.

docs/type-reference/native.md

Lines changed: 0 additions & 16 deletions
This file was deleted.

docs/type-reference/union.md

Lines changed: 0 additions & 19 deletions
This file was deleted.

0 commit comments

Comments
 (0)