Following #2000 and #2046 we can't `pop` the current value when assigning
a new one (which was probably the most efficient) as we want to keep the
order in the `__dict__`.
So let's do a shallow copy of the `__dict__` without the current value
fix#2073
* don't pop the value off __dict__
* adding change description
* still pop the field, but catch any exc, set the field to og value, and reraise exc
* adding tests
* fixing test
* improve tests/test_validators.py tests
Co-authored-by: John Sabath <john.sabath@equipmentshare.com>
Co-authored-by: Samuel Colvin <samcolvin@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 ability to read secrets from files
* Added docs and updated tests to handle new _build_values argument
* Updated docs to note which types are loaded
* Updated deep_update to take a list of update mappings
* Added warning when fields are not defined as a secret type
* Address additional PR feedback
* improve documentation
* remove redundant UserWarning lines
* allow any field type, not just SecretStr
* regex escape paths in windows 😴
* skip tests on windows 😧🔫
Co-authored-by: Samuel Colvin <s@muelcolvin.com>
* 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.
* call validator with correct "values" type in BaseModel.__setattr__
* Fix code review comments
- use `self.__dict__` as the values parameter
- refine changed markdown
Co-authored-by: Ran Shaham <ransh@mobileye.com>
* Add ability to use min_length/max_length constraints with secret types
* Add change file
* Remove StrLike and BytestLike classes
* Add ability to define constraints for a custom class
* Fix issue with incorrect secrets schema generation
* Add schema test for SecretStr and SecretBytes
* Add test to cover valid secret length
* Fix representation of literal enums (#1747)
Use existing is_literal_type
Skip when typing_extensions is not present
Improvements proposed by PrettyWood reviewing PR
* Trim unnecessary logic
* Clarify behaviour
* extend test slightly
Co-authored-by: Samuel Colvin <s@muelcolvin.com>
* ignore Pipfile, .lock files
* add ref_template option
use a string.Template instead of a ref_prefix to allow for more varied`$ref`s to be created.
Template string is expected to have $model_name `identifier `
* formatting / linting
* add changes
* typo
* use string.format instead of string.Template
* remove ref_prefix default
if no `ref_prefix` provided, use the `template_default`
* use ref_template in field_singleton_schema
* fix test_schema_with_ref_template
* add parameters for `test_schema_with_refs`
test name change
test for key error
* provide ref_template default argument
* fix linting
* fix mypy and coverage
* docs and correct model_schema usage
* fastAPI tests actualy caught an error
* linting
Co-authored-by: Samuel Colvin <s@muelcolvin.com>
* Parse timezone information in time str
* Add description of change fixing issue 1744
* Guard against TZ over 24 hours
* Parse timezone information in time str
* Datetime and time TZ parsed in separate fn
* Sharpen annotation, many return statements
* Fix mypy errors raised on datetime_parse
* fix type hints
* update docs and correct types
Co-authored-by: Samuel Colvin <s@muelcolvin.com>
* Add __init__ for ForwardRef stub
* Add changes file
* Update changes/1738-sirtelemak.md
Co-authored-by: Samuel Colvin <samcolvin@gmail.com>
* Add mypy check for ForwardRef
* Add Black line after if statement
Co-authored-by: Samuel Colvin <samcolvin@gmail.com>
Co-authored-by: Sergey Teplyakov <s.teplyakov@fitingo.com>
Co-authored-by: Samuel Colvin <s@muelcolvin.com>
* 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 pickle support to dynamically created models
* Add created model module check
* Use globals() to retrieve model
* Use single quotes
* use mocker instead of mock
Co-authored-by: PrettyWood <em.jolibois@gmail.com>
* remove unused import
* add test for dynamic forward ref
* move generic test to test_generics.py
* fix test_generic_model_pickle test, add additional check for <locals> in create_model
* fix code style
* resolve issues with global/local models
* make ensure_picklable return given model
* remove ensure_picklable, use test_is_call_from_module only in generics
* reformat code after updating black==20.8b1
* move get_caller_module_name and is_call_from_module to generics
* apply suggestions from @samuelcolvin
* add tests for get_caller_module and is_call_from_module called from module
* fix linting
* fix path to modules in test_module fixture, capture stderr and stdout
* fix broken test module
* fix subprocess call for windows
* enhance create_module fixture, add run_as_module fixture
this will allow run modules in subprocess and define module code in functions-containers
* add test for redefined concrete model without cache
* add changes file
* remove unused variable
* rewrite tests with pytest.raises
* fix linting
* rewrite test_create_model_pickle and test_forward_ref_with_create_model with module definition in function
* Update create_model docstring
Co-authored-by: PrettyWood <em.jolibois@gmail.com>
Co-authored-by: Samuel Colvin <s@muelcolvin.com>
* feat(field): add Enum type support
closes#1735
* test: add extra cases and rename to be more explicit
* refactor: rename enum_validator
* feat: add Enum and IntEnum types support
* docs: add new types
* chore: update change message
* feat: use partially get_origin and get_args from typing
Rework of d86a184072655d93652d6ea941421005f34de962 by @hmvp
We cannot directly use `typing.get_origin` and `typing.get_args` for
our custom types for which args and origin are wrong by default.
But at least we now have a unified behaviour, which can be improved
in the near future
* feat: add fallback in `get_args` for generics in python 3.9
* feat: add new `_evaluate` for python 3.9
In python 3.9, `typing._evaluate` has a new required
positional argument `recursive_guard`
* chore: add pragma no cover for python 3.9 fallbacks
* chore: add change file
* chore: add comments
* feat(ci): add python 3.9 support
* fix: mypy assumption is wrong
* refactor(schema): put schema data from fieldinfo in dedicated function
* feat(schema): support custom title, description and default for enums
closes#1748
* refactor: replace $ref by allOf + $ref to be supported by doc generation tools
* fix: do not set title by default for enums
* refactor: make code more explicit
* fix: run linter
* fix: forward ref with nested models and optional fields
PR #1712 introduced a regression for forward refs in `ModelField.prepare`
as it would not return early for forward refs anymore.
Optional fields would hence have `required` set to `True`.
closes#1736
* test: skip python 3.6 as __future__.annotations is not defined
* fix: validate nested models with `default_factory`
PR #1504 introduced a regression by bypassing `populate_validators()`,
which would skip the validation of children in nested models
with `default_factory`
closes#1710
* test: add example of nested models parsing with `default_factory`
closes#1717
* add testcase from #1722
* bodge for benchmarks
Co-authored-by: Samuel Colvin <s@muelcolvin.com>
* Fix nested all include exclude
* Ensure original exclude value is not modified
This commit also fixes some weird cases in the recursive
`update_normalized_all` call and Ellipsis values.
* Add docstring, parametrize tests
* Fix master
* Fix master 2 (#1694)
* test: add regression test with wrong type default
* fix: remove always on conlist and conset
* fix: use utf8 as default encoding on all OS
* conset invalid defualt test
* add change
Co-authored-by: PrettyWood <em.jolibois@gmail.com>