* fix: ignore `__doc__` as valid private attribute (#2091)
closes#2090
* Fixes a regression where Enum fields would not propagate keyword arguments to the schema (#2109)
fix#2108
* Fix schema extra not being included when field type is Enum
* Code format
* More code format
* Add changes file
Co-authored-by: Ben Martineau <b.martineau@iwoca.co.uk>
* fix: update all modified field values in `root_validator` when `validate_assignment` is on (#2119)
* fix: update all modified field values in `root_validator` when `validate_assignment` is on
closes#2116
* chore: update root_validator name
Co-authored-by: Arthur Pastel <arthur.pastel@gmail.com>
Co-authored-by: Arthur Pastel <arthur.pastel@gmail.com>
* fix: support `underscore_attrs_are_private` with generic models (#2139)
closes#2138
* fix: set right default value for required (optional) fields (#2143)
closes#2142
* Fix#2111: support pickle for built-in dataclasses (#2114)
* 2111: support pickle for built-in dataclasses
* 2111: add changes
* 2111: simplify test
* return original name + handle similar names
* add additional check
* fix a misspell
* remove useless f-string
* cleanup test
Co-authored-by: Samuel Colvin <s@muelcolvin.com>
* uprev and add history
* tempoarily pin pip
Co-authored-by: Eric Jolibois <em.jolibois@gmail.com>
Co-authored-by: Ben Martineau <bm424@cam.ac.uk>
Co-authored-by: Ben Martineau <b.martineau@iwoca.co.uk>
Co-authored-by: Arthur Pastel <arthur.pastel@gmail.com>
Co-authored-by: aimestereo <aimestereo@gmail.com>
* feat: add validator for NoneType
closes#2095
* feat: support NoneType directly as type
* chore: add change file
* chore: fix typo
* fix: handle Literal[None] for python3.6/3.7 without typing_extensions
* chore: move NotNoneError and export it
* chore: use constant NONE_TYPES to simplify a bit
* chore: use check on Literal instead of typing_extensions
These tests would not run on python 3.8+ without typing_extensions
even though Literal is defined
* test: use fresh Literal[None] in test case
* feat: handle `None` type in schema
* docs: add NoneType documentation
* refactor: switch NONE_TYPES from tuple to set
* Fix#947, fix#1483, fix#1247 allow inner type vars to be present in parent generic classes
- Rename generics._is_type to _is_generic in response to comment:
https://github.com/samuelcolvin/pydantic/pull/1989#discussion_r503400391
- Add more explicit type assertion in generics test
- Add generics tests and unify naming
- Move deep generic tests all into same place in code
- Unify naming convention in deep generic tests using naming of existing tests
- Add tests for multiple inheritance and multiple type vars
- Add generic tests for type hint resolution cases
- Fix edge cases for handling parameters in generic models
- Resolve parameters correctly
- Add tests for special cases like callables
- Add returning generic type directly if parameters and arguments are
identical.
* Apply review comments
- Add docstrings
- Small refactor `generics.__concrete_name__`
- Small refactor of `generics.resolve_type_hints`
- Change `is_identity_typevars_map` to more generic and clearer
`all_identical` and move into utils.
- rename "resolve_type_hint" to "replace_types" so as to not get
confused with "resolve_annotations" from `pydantic.typing`
* Fix generics test coverage
* Update pydantic/generics.py, remove unneeded annotation
mypy understands list comprehensions as they are now
Co-authored-by: Eric Jolibois <em.jolibois@gmail.com>
Co-authored-by: Eric Jolibois <em.jolibois@gmail.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>
* 2111: support pickle for built-in dataclasses
* 2111: add changes
* 2111: simplify test
* return original name + handle similar names
* add additional check
* fix a misspell
* remove useless f-string
* cleanup test
Co-authored-by: Samuel Colvin <s@muelcolvin.com>
Following #2030, the requirements to build the documentation are not installed
with the rest making `make docs` crash when following the contributing steps.
As `make install` is only used for this purpose (easy onboarding), let's just add
again the installation of the doc requirements with it
* fix: update all modified field values in `root_validator` when `validate_assignment` is on
closes#2116
* chore: update root_validator name
Co-authored-by: Arthur Pastel <arthur.pastel@gmail.com>
Co-authored-by: Arthur Pastel <arthur.pastel@gmail.com>
As someone started using pydantic, it can be very convenient to know what type we can rely the returned field is, so we know what we can check on it and what fields it has.
After searching the code I found out it has to be of type ModelField and that's why I'm offering it here as something that I think should be clarified in the documentation.
fix#2108
* Fix schema extra not being included when field type is Enum
* Code format
* More code format
* Add changes file
Co-authored-by: Ben Martineau <b.martineau@iwoca.co.uk>
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>
* include assert in valudator test in pytest
* remove try_assert execution in Makefile
* use pytest.raises
* add newline
* tweak
* undo my mistake
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