more python notes

This commit is contained in:
Thomas Bishop 2026-01-11 18:27:51 +00:00
parent 0790cd2218
commit abb92d9f2b
2 changed files with 19 additions and 0 deletions

View file

@ -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

View file

@ -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