From a65dda032ddb5fce2493a77816072d65bdfc2e8a Mon Sep 17 00:00:00 2001 From: ringeringeraja Date: Fri, 25 Aug 2023 21:18:20 -0300 Subject: [PATCH] readme --- README.md | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 68065cc..f7c5431 100644 --- a/README.md +++ b/README.md @@ -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 }) @@ -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({ @@ -72,6 +73,11 @@ result = m.validate({ } """ print(result) + +""" +{} +""" +print(m.cast({})) ``` ## License