more python notes
This commit is contained in:
parent
0790cd2218
commit
abb92d9f2b
2 changed files with 19 additions and 0 deletions
|
|
@ -52,6 +52,21 @@ class VariantProperties(CommonProperties):
|
|||
> Note that the `BaseModel` must "drill-down"; it must be inherited at each
|
||||
> stage.
|
||||
|
||||
## Transform incoming values (before validation)
|
||||
|
||||
In the following example I convert an incoming `str` value to a list of strings:
|
||||
|
||||
```py
|
||||
class MySchema(BaseModel)
|
||||
sub_genres: Optional[List[str]] = None)
|
||||
@field_validator("sub_genres", mode="before")
|
||||
@classmethod
|
||||
def string_to_list(cls, v):
|
||||
if isinstance(v, str):
|
||||
return [v]
|
||||
return v
|
||||
```
|
||||
|
||||
## Aliasing
|
||||
|
||||
Sometimes the incoming data that you wish to validate will have field names
|
||||
|
|
|
|||
|
|
@ -86,3 +86,7 @@ Then to specify the units that will run as the `yield` we just inject `setup`:
|
|||
def some_function(setup_function):
|
||||
pass
|
||||
```
|
||||
|
||||
## Example: setting up mocks before every test
|
||||
|
||||
We can combine the
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue