Skip to content

Commit

Permalink
readme
Browse files Browse the repository at this point in the history
  • Loading branch information
minenwerfer committed Aug 26, 2023
1 parent 348bc17 commit a65dda0
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Animal = typing.TypedDict('Animal', {

# even another TypedDicts can be used!
Person = typing.TypedDict('Person', {
'name': str,
'name': typing.NotRequired[str | None],
'age': int,
'animal': Animal
})
Expand All @@ -40,13 +40,14 @@ m = model(Person, {
'Animal': Animal
})

# hooks can be implemented using monkeypatching
# setting default values also can be achieved this way
old_validate = m.validate
def new_validate(target: Person):
new = target.copy()
new['name'] = new['name'].capitalize()
new['name'] = new.get('name', 'unknown')
return validate(Person, typing.cast(typing.Any, new))

# hooks can be implemented using monkeypatching
m.validate = new_validate

result = m.validate({
Expand All @@ -72,6 +73,11 @@ result = m.validate({
}
"""
print(result)

"""
{}
"""
print(m.cast({}))
```

## License
Expand Down

0 comments on commit a65dda0

Please sign in to comment.