Commit Graph

24 Commits

Author SHA1 Message Date
Eric Jolibois c38c463137 feat: add Config.smart_union option (#2092)
* feat: add `Config.smart_union` to prevent coercion in `Union` if possible

* docs: write some documentation

* Update docs/usage/model_config.md

Thanks @djpugh

Co-authored-by: David J Pugh <6003255+djpugh@users.noreply.github.com>

* improve doc

* support 3.10

* improve smart_union

* Update docs/usage/types.md

Co-authored-by: David J Pugh <6003255+djpugh@users.noreply.github.com>

* put new sentence inside warning block

* docs: reorder

* rename is_union_origin into is_union

* inverse and condition for perf

* fix doc

Co-authored-by: David J Pugh <6003255+djpugh@users.noreply.github.com>
2021-12-07 21:58:52 +00:00
Eric Jolibois f9c65c5b88 fix: add/fix BaseConfig type annotations (#2720) 2021-09-04 04:13:20 +02:00
Nuno André b718e8e626 Add GetterDict example (#2463)
* Add GetterDict example

* Update docs/usage/models.md

Co-authored-by: Samuel Colvin <samcolvin@gmail.com>

Co-authored-by: Samuel Colvin <samcolvin@gmail.com>
2021-05-12 15:25:17 +01:00
wackazong 7fb77a779a Documentation: Put examples for config to the start of the section (#2615)
* Put examples to the start of the section

I think this is where they belong, they were in the middle of the list of config options somewhere near the end.

* Add "options" in table of contents

* tweak

Co-authored-by: Eric Jolibois <em.jolibois@gmail.com>
2021-04-05 12:40:13 +02:00
Samuel Colvin aff4a41f9d preparing for v1.8 (#2414)
* preparing for v1.8 🎉 🚀

* change description for #2415

* tweak change descriptions

* fix nested lists in docs

* remove items in 1.7.3 from 1.8
2021-02-26 16:30:08 +00:00
Raphael Huille d8e8e6a780 Generate a hash function when frozen is True (#1881)
* feature: add a `frozen` parameter to config

For now, `frozen` is a strict duplication of `allow_mutation` parameter
i.e. setting `frozen=True` does everything that `allow_mutation=False` does.

NB: this does not change the behavior of `allow_mutation`.

In next commit, setting `frozen=True` will also make the BaseModel hashable
while the existing behavior of `allow_mutation` will not be updated.

* refactor: factorise immutability tests

* feature: generate a hash function when frozen is True

Now, setting `frozen=True` also generate a hash function for the model
i.e. `__hash__` is not `None`. This makes instances of the model potentially
hashable if all the attributes are hashable. (default: `False`)

* reviewer feedback: use hash of the class instead of the super

* reviewer feedback: fix spelling checks

* reviewer feedback: update changes description

* test: remwork mypy tests in order to catch only frozen related errors

Before: there were errors about other stuff than frozen behavior
After: The modification catch only errot related to the frozen behavior

* test: split test_immutablity in 2 functions

One function tests the behavior: 'the model is mutable'
The other tests the behavior:OC 'the model is immutable'

* test mutability: remove the unnecessary parametrization

* test immutability: remove assertion that do not test frozen behavior
2021-02-23 11:45:40 +00:00
Arseny Boykov ce67660d2f Allow to configure models through class kwargs (#2356)
* add support for class kwargs config

* reformat tests

* add changes file and docs

* fix linting in 'inherit_config'

* tweak docs

Co-authored-by: Samuel Colvin <s@muelcolvin.com>
2021-02-22 17:10:04 +00:00
Eric Jolibois f11b3ae313 feat: avoid reconstructing models used as fields of another model on validation (#2193)
* feat: avoid reconstructing models used as fields of another model on validation

closes #265
closes #1837

* docs: add section to change config

* change default value to avoid breaking change

* refactor: only suggest custom BaseModel approach
2021-02-12 13:04:52 +00:00
Eyitayo Ogunbiyi 61b45340e7 Feature/add anystr lower to config (#2183)
* added anystr_lower field to config

* updated docs with any anystr_lower config property

* updated changes folder with markdown describing new change

* added anystr to _validators list under bytes type

* added unit tests for anystr_lower config

* Update pydantic/validators.py

Fix wrong method used in cosntr_lower

Co-authored-by: Eric Jolibois <em.jolibois@gmail.com>

* added lower_str to conbytes and constr functions

* Update changes/2134-tayoogunbiyi.md

Co-authored-by: Samuel Colvin <samcolvin@gmail.com>

* renamed conbytes & constr paramater name

* updated change markdown

* added docs for args to constr and conbytes

* added examples to showing to_lower functionality in conbytes & constr

* added better description for curtail_length

* removed unessary whitespace, added default and types in docs

* Update changes/2134-tayoogunbiyi.md

Co-authored-by: Eric Jolibois <em.jolibois@gmail.com>

* added single whitespace to arguments list under constr & conbytes

Co-authored-by: Eric Jolibois <em.jolibois@gmail.com>
Co-authored-by: Samuel Colvin <samcolvin@gmail.com>
Co-authored-by: Samuel Colvin <s@muelcolvin.com>
2021-02-12 12:28:08 +00:00
Arseny Boykov 664cbcfc01 Add private attributes support (#1679)
* Add private attributes support

* Add more blank lines in example

* Add changes file

* Update docs/usage/models.md

Co-authored-by: Samuel Colvin <samcolvin@gmail.com>

* fix after bad merge

* Add PrivateAttr, Config.underscore_attrs_are_private

* remove unrelated change in utils.py

* add   # noqa: C901 (ignore complexity) to __setattr__
(see comment in PR)

* add annotation to Config.underscore_attrs_are_private

Co-authored-by: Samuel Colvin <samcolvin@gmail.com>

* use sunder names

* mention underscore_attrs_are_private in model_config.md

* add comment about default factory

* fix comment

* fix comment

* clarify that both dunder and sunder names might be used

* tweak docs and name

* _set_default_private_attributes -> _init_private_attributes

Co-authored-by: Samuel Colvin <samcolvin@gmail.com>

* use new name _init_private_attributes

* move tests

* copy private attributes in BaseModel.copy()

* add test for default and default_factory used together

* fix linting

* more tests, default_factory kw only

Co-authored-by: Samuel Colvin <samcolvin@gmail.com>
Co-authored-by: Samuel Colvin <s@muelcolvin.com>
2020-10-26 09:47:40 +00:00
Samuel Colvin f85afab8cf tiny correction to docs 2020-06-27 13:58:23 +01:00
Wesley Ellis be95ddaf88 Be more specific about the meaning of Config.extra (#1203)
* Be more specific about the meaning of Config.extra

When reading through the docs as a beginner, it was not clear to me what the difference between `'allow'` and `'ignore'` was. I fixed this by adding a short description of each of the options from what I can tell from reading the source code.

Is there a better way to format this? Maybe as a list?


(ps, thanks for the cool library)

* tiny further clarification

* sorry...

Co-authored-by: Samuel Colvin <samcolvin@gmail.com>
2020-02-02 12:15:42 +00:00
Samuel Colvin 943a8a06e5 change alias priority logic (#1178)
* fix alias priority so alias_generators don't take priority

* improve test names

* remove debugs

* Apply suggestions from code review

* more tests and allow custom alias_priority on fields

* precedence tests and docs

* tweaks and add change

* suggestions
2020-01-24 10:31:16 +00:00
Samuel Colvin 02784fb83b docs typo 2020-01-19 18:28:11 +00:00
Sebastián Ramírez aeba494388 Add support for generics with __get_validators__ (#1159)
*  Add support for generics with __get_validators__

*  Add tests for Generics with __get_validators__

* 📝 Add change note

*  Add support for Generic fields with validation of sub-types

* 📝 Add docs for arbitrary generic types

*  Add tests for generic sub-type validation

* 📝 Update change note. Generic support is not so "basic" now

* 📝 Update docs with code review

* ♻️ Update fields module with code review changes

*  Update tests from code review

* 📝 Update example for generics, try to simplify and explain better

* tweak docs example

Co-authored-by: Samuel Colvin <samcolvin@gmail.com>
2020-01-17 16:22:54 +00:00
Selim Belhaouane bdc3973d90 Allow schema_extra to be a callable (#1054)
* fixes for Windows development

* Allow Config.schema_extra to be a callable
2019-12-09 11:01:17 +00:00
Samuel Colvin 92c9b10a75 clarify meaning of camel case, fix #1056 (#1063) 2019-12-02 13:10:39 +00:00
Samuel Colvin 17b5ff42c1 renaming docs examples (#972)
* renaming docs examples

* tweaks
2019-11-07 14:40:44 +00:00
retnikt dccc4014dc Clarify documentation and error message about keep_untouched (#926)
* Clarify keep_untouched documentation (#924)

* Clarify error message for custom types (#924)

* Fix tests for changed error message (#924)

* fix formatting

* remove erroneous error message and add change
2019-10-23 11:14:51 +01:00
Samuel Colvin ed7b216e5f Change alias precedence to prefer child models (#904)
* Change alias precedence to prefer child models

* add docs about alias precedence

* correct change
2019-10-17 10:58:28 +01:00
Samuel Colvin e7227db41a Insert prints in docs. (#895)
* starting insert prints

* working exec_script

* remove prints, fix exec_examples.py

* more cleanup of examples, better model printing

* upgrade netlify runtime

* extra docs deps

* few more small tweaks
2019-10-14 16:40:25 +01:00
dmontagu beb57364d2 Lots of minor docs tweaks (#877)
* Lots of minor changes

* More tweaks

* Remove git conflicts

* suggested tweaks
2019-10-10 12:00:22 +01:00
Samuel Colvin ae34a6a733 rename allow_population_by_alias -> allow_population_by_field_name (#875)
* rename allow_population_by_alias -> allow_population_by_field_name, fix #585

* add change

* tweak PR template ☣️

* tweak Makefile
2019-10-07 18:40:01 +01:00
Samuel Colvin 33b7d52d31 moving docs to mkdocs (#856)
* moving docs to mkdocs

* transfering readme to md and more

* fixing build

* splitting usage.md

* improving schema.md and index.md

* fix make_history.rst

* models intro

* working on data conversation and required fields

* more fixes to models.md

* list all standard types supported

* list of pydantic types

* tweaks

* update links in code

* Apply suggestions from code review

incorporate @dmontagu's suggestions.

Co-Authored-By: dmontagu <35119617+dmontagu@users.noreply.github.com>

* Apply suggestions from code review

more missed suggestions.

Co-Authored-By: dmontagu <35119617+dmontagu@users.noreply.github.com>

* Apply suggestions from code review

more corrects.

* cleanup

* Field order warning

* fix and regenerate benchmarks

* format examples better, cleanup

* improve schema mapping table

* correct highlighting file types in schema.md

* add redirects in javascript

* add logo
2019-10-07 17:19:01 +01:00