* add support for alias handling in validate_arguments
* add test for alias handling in validate_arguments
* add documentation on alias support for decorator
* bug fixed in the validate_argumen decorator documentation
* add changes README
* change in the documentation due to a drafting error
* Update changes/3019-MAD-py.md
Co-authored-by: Eric Jolibois <em.jolibois@gmail.com>
* more challenging tests
* run the format checker
* integration of empty string as alias
Co-authored-by: Eric Jolibois <em.jolibois@gmail.com>
Co-authored-by: Samuel Colvin <s@muelcolvin.com>
* fix: handle basemodel fallback for custom encoders
* put back old behaviour and add to_dict
* typo
Co-authored-by: Christian Bundy <christianbundy@fraction.io>
Co-authored-by: Christian Bundy <christianbundy@fraction.io>
* Add RabbitmqDsn
Will update once finished - haven't looked at the CONTRIB yet. Want to test locally to see if it works.
* added tests; added to docs
* added changes
* fixed import in networks.py
* fixed linting issues; fixed __init__.py import issue
* sorted imports
* added trailing comma on imports
* Merge master
* Change class name from RabbitmqDsn to RabbitMqDsn
* Format code
* Rename change file and prettify content
* Fix RabbitMQ name on documentation
* Add a trivial test
* Address Samuel and Nuno's comments
* Refactor AMQP tests according to Redis tests style
* Update docs/examples/settings_main.py
* cleanup
Co-authored-by: Thomas <thomas@9bitbyte.com>
Co-authored-by: Thomas Crha <tom.crha@dragonflytechnologies.com>
Co-authored-by: Samuel Colvin <s@muelcolvin.com>
* Try to evaluate forward refs after model created
* Upadate docs and remove code duplication
* Update changes/2588-uriyyo.md
Co-authored-by: Eric Jolibois <em.jolibois@gmail.com>
* Update docs/usage/postponed_annotations.md
Co-authored-by: Eric Jolibois <em.jolibois@gmail.com>
* Remove unused import
Co-authored-by: Eric Jolibois <em.jolibois@gmail.com>
* Add GetterDict example
* Update docs/usage/models.md
Co-authored-by: Samuel Colvin <samcolvin@gmail.com>
Co-authored-by: Samuel Colvin <samcolvin@gmail.com>
* Add exclude/include as field parameters
- Add "exclude" / "include" as a field parameter so that it can be
configured using model config (or fields) instead of purely at
`.dict` / `.json` export time.
- Unify merging logic of advanced include/exclude fields
- Add tests for merging logic and field/config exclude/include params
- Closes#660
* Precompute include/exclude fields for class
* Increase test coverage
* Remove (now) redundant type checks in Model._iter: New
exclusion/inclusion algorithms guarantee that no sets are passed further down.
* Add docs for advanced field level exclude/include settings
* Minimal optimization for simple exclude/include export
Running benchmarks this vs. master is at:
this: pydantic best=33.225μs/iter avg=33.940μs/iter stdev=1.120μs/iter version=1.7.3
master: pydantic best=32.901μs/iter avg=33.276μs/iter stdev=0.242μs/iter version=1.7.3
* Apply review comments on exclude/enclude field arguments
* Fix/simplify type annotations
* Allow both ``True`` and ``Ellipsis`` to be used to indicate full field
exclusion
* Reenable hypothesis plugin (removed by mistake)
* Update advanced include/include docs to use ``True`` instead of ``...``
* Move field info exclude/include updates into FieldInfo class
This way, the model field object does not need to concern itself with
dealing with field into specific fields.
(Same was done for alias in a previous commit).
* remove double back tick in markdown.
Co-authored-by: Samuel Colvin <samcolvin@gmail.com>
* Support `Field` in `dataclass` + `'metadata'` kwarg of `dataclasses.field`
Please enter the commit message for your changes. Lines starting
* add `__has_field_info_default__` for minimal effect on perf
* lower complexity of `_process_class`
* 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>
* Infer root type from Annotated
* Extract Field from Annotated
* Add changelog
* Extend existing get_args/get_origin
* Fix Annotated on py3.6 without typing-extensions
* Handle Ellipsis default
* Fix field reuse after FieldInfo.default mutation
* Fix ci
* fix(decorator): detect when a duplicate argument is passed in
Currently, it is possible to override a positional argument with a keyword
argument using the decorator.
In native python, this raises a TypeError.
Detect this usecase, to prevent keywords overriding positional parameters.
Closes: https://github.com/samuelcolvin/pydantic/issues/2249
* add changelog entry
* fix docs example to not override positional argument
Co-authored-by: Samuel Colvin <s@muelcolvin.com>
* feat: add support for `NamedTuple` and `TypedDict` types
* support `total=False`
* tests: fix ci with python < 3.8 without typing-extensions
* chore: improve mypy
* chore: @samuelcolvin remarks
* refactor: move tests in dedicated file
* docs: add annotated types section with examples
* feat: support properly required and optional fields
* chore(deps-dev): bump typing_extensions
* docs: add a note for `typing_extensions`
* chore: update message to be more accurate
* feat: pass down config to created models
* feat: add util methods to create model from TypedDict or NamedTuple
* refactor: rename into typeddict and namedtuple
* test: add utils tests
* chore: fix lint
* chore: improve test
* refactor: rename utils to match the rest
* chore: update change
* docs: add section for create_model_from_{namedtuple,typeddict}
* refactor: rename typed_dict/named_tuple
* feat: support schema with TypedDict
* feat: support schema for NamedTuple
* feat: add json support for NamedTuple
* chore: rewording
* refactor: use parse_obj
* fix: add check for max items in tuple
* docs: separate typing.NamedTuple and collections.namedtuple
* feat: avoid reconstructing models used as fields of another model on validation
closes#265closes#1837
* docs: add section to change config
* change default value to avoid breaking change
* refactor: only suggest custom BaseModel approach
* 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>
* feat: Add the ability to add extra settings sources
* doc: Document "customise settings sources" feature
* tests: Add missing test and add change file
* Update changes/2107-kozlek.md
Co-authored-by: Eric Jolibois <em.jolibois@gmail.com>
* improve docs for settings customise_sources
* fix docs building
* fix test :-(
Co-authored-by: Thomas Berdy <thomas.berdy@outlook.com>
Co-authored-by: Eric Jolibois <em.jolibois@gmail.com>
Co-authored-by: Samuel Colvin <s@muelcolvin.com>
* Added StrictBytes type
* updated tests for StrictBytes, updated relevant sections in documentation for StrictBytes and ConstrainedBytes
* added changelog
* chore: typo in change
Co-authored-by: Eric Jolibois <em.jolibois@gmail.com>
* fix: pydantic dataclasses can inherit from stdlib dataclasses
closes#2042
* docs: add some documentation
* fix: support arbitrary_types_allowed with stdlib dataclass
closes#2054
* docs: add documentation for custom types
* feat: pydantic dataclasses support built-in ones
closes#744
* feat: improve dataclass typing
* feat: add support for nested dataclasses
closes#1743
* feat: support dataclass schema with nested dataclasses
* refactor: remove `_dataclass_with_validation` function
* docs: add docstring for `make_dataclass_validator`
* refactor: rename DataclassType into Dataclass
The name `DataclassType` was missleading as it's not a `Type` per say.
* refactor: change global `dataclass` import to local
pydantic import time was improved in
https://github.com/samuelcolvin/pydantic/pull/1132
by keeping `dataclass` import local. So let's keep it that way!
* test: add extra nested case with BaseModel
* chore: s/pydantic/_pydantic_/g
* docs: add some documentation
* 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>
* Allow generics to extend concrete classes. fixes#2005
* Update the docs
* Updote the changes
* Convert double quotes to single quotes
* Fix formatting
* Add a check for data
* Update example
* Add a skip_36 decorator that got accidentally deleted when resolving conflicts.
* linting as a separate ci step
* CI and docs improvements
* fix docs preview
* fix docs, benchmarks fastapi tests
* fix formatting and docs build
* tweak publishing docs
* fix for new download-artifact action
* skip check tag to check docs build
* prepare for merge
* add description of subclass each_item scenario
* add example of subclass validator with each_item
* each_item causes validator to not run when parent class has List field #1566
* Add datamodel-code-generator link in pydantic document site.
* tweak menu
* fix blank lines
Co-authored-by: Samuel Colvin <samcolvin@gmail.com>
Co-authored-by: Samuel Colvin <s@muelcolvin.com>