diff --git a/docs/usage.md b/docs/usage.md index 817afe5..00bb4d7 100644 --- a/docs/usage.md +++ b/docs/usage.md @@ -174,7 +174,7 @@ be raised. A schema can be added after instantiation through a setter: config.schema = MySchema ``` -## Casting and default values +### Casting and default values By default, `maison` will replace the values in the config with whatever comes back from the validation. For example, for a config file that looks like this: @@ -187,7 +187,11 @@ foo = 1 And a schema that looks like this: ```python +from pydantic import BaseModel, ConfigDict + class MySchema(BaseModel): + model_config = ConfigDict(coerce_numbers_to_str=True) + foo: str bar: str = "my_default" ``` diff --git a/tests/unit/test_config.py b/tests/unit/test_config.py index 3bb942f..9b02c6c 100644 --- a/tests/unit/test_config.py +++ b/tests/unit/test_config.py @@ -5,6 +5,7 @@ import pytest from pydantic import BaseModel +from pydantic import ConfigDict from pydantic import ValidationError from maison.config import UserConfig @@ -205,9 +206,11 @@ def test_use_schema_values( ) -> None: """Config values can be cast to the validated values.""" - class Schema(BaseModel, coerce_numbers_to_str=True): + class Schema(BaseModel): """Defines schema.""" + model_config = ConfigDict(coerce_numbers_to_str=True) + bar: str other: str = "hello" @@ -229,9 +232,11 @@ def test_not_use_schema_values( ) -> None: """If `use_schema_values` is set to False then don't use validated values.""" - class Schema(BaseModel, coerce_numbers_to_str=True): + class Schema(BaseModel): """Defines schema.""" + model_config = ConfigDict(coerce_numbers_to_str=True) + bar: str other: str = "hello"