Skip to content

Commit

Permalink
Clarify documentation and error message about keep_untouched (pydanti…
Browse files Browse the repository at this point in the history
…c#926)

* Clarify keep_untouched documentation (pydantic#924)

* Clarify error message for custom types (pydantic#924)

* Fix tests for changed error message (pydantic#924)

* fix formatting

* remove erroneous error message and add change
  • Loading branch information
retnikt authored and samuelcolvin committed Oct 23, 2019
1 parent bab6970 commit dccc401
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 6 deletions.
1 change: 1 addition & 0 deletions changes/926-retnikt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Clarify usage of `remove_untouched`, improve error message for types with no validators.
4 changes: 2 additions & 2 deletions docs/usage/model_config.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ Options:
: a callable that takes a field name and returns an alias for it

**`keep_untouched`**
: a tuple of types (e.g. descriptors) that should not be changed during model creation and will not be
included in the model schemas
: a tuple of types (e.g. descriptors) for a model's default values that should not be changed during model creation and will
not be included in the model schemas. **Note**: this means that attributes on the model with *defaults of this type*, not *annotations of this type*, will be left alone.

**`schema_extra`**
: a `dict` used to extend/update the generated JSON Schema
Expand Down
4 changes: 1 addition & 3 deletions pydantic/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -568,9 +568,7 @@ def find_validators( # noqa: C901 (ignore complexity)
if config.arbitrary_types_allowed:
yield make_arbitrary_type_validator(type_)
else:
raise RuntimeError(
f'no validator found for {type_} see `keep_untouched` or `arbitrary_types_allowed` in Config'
)
raise RuntimeError(f'no validator found for {type_}, see `arbitrary_types_allowed` in Config')


def _find_supertype(type_: AnyType) -> Optional[AnyType]:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -953,7 +953,7 @@ def class_name(cls) -> str:

assert str(e.value) == (
"no validator found for <class 'tests.test_main.test_custom_types_fail_without_keep_untouched.<locals>."
"_ClassPropertyDescriptor'> see `keep_untouched` or `arbitrary_types_allowed` in Config"
"_ClassPropertyDescriptor'>, see `arbitrary_types_allowed` in Config"
)

class Model(BaseModel):
Expand Down

0 comments on commit dccc401

Please sign in to comment.