-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
enes.aksu
committed
Jan 1, 2020
1 parent
6938de6
commit afdca50
Showing
1 changed file
with
40 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# dataclass_plus | ||
|
||
The `dataclass_plus` is a fastest type validation library for the `dataclass` | ||
|
||
|
||
## Example | ||
|
||
|
||
```python | ||
from dataclass_plus import dataclass_plus | ||
from typing import List, Dict, Tuple | ||
|
||
|
||
@dataclass_plus | ||
class Model: | ||
id: int | ||
name: str | ||
dict_example: Dict[str, str] | ||
list_example: List[int] # this field is required | ||
tuple_example: Tuple[str, float] = None # this field is not required because set default None | ||
|
||
|
||
Model( | ||
id=1, | ||
name='Test Test', | ||
dict_example={"test": "test"}, | ||
list_example=[1,2], | ||
tuple_example=("test", 1.2) | ||
) | ||
# => Model(id=1, name='Test Test', dict_example={"test": "test"}, list_example=[1,2], tuple_example=("test", 1.2)) | ||
# Invalid Model | ||
Model( | ||
id=1, | ||
name='Test Test', | ||
dict_example={"test": 1}, | ||
list_example=[1,2], | ||
tuple_example=("test", 1.2) | ||
) | ||
# => ValueError: {'test': 1} is not typing.Dict[str, str] | ||
``` |