* allow Config.field to update a Field, fix#2426
* move logic to update_from_config, work with Annotated
* fix flake8 erroneous warnings
* test for allow_mutation
* better support for allow_mutation
* fix: support properly `Enum` when combined with generic models
* whitelist iterables
* update change description
* add test for Literal
Co-authored-by: Samuel Colvin <s@muelcolvin.com>
* added method to generate a constrained float with multiple_of argument
* removed HealthCheck.filter_too_much
* Added change file
* fixes for case when min/max aren't provided; adding an extra test for float gt/lt with multiple of
* add tests that should pass
But we have those errors
226: error: Item "str" of "Union[UUID, str]" has no attribute "hex" [union-attr]
227: error: Item "str" of "Union[UUID, str]" has no attribute "hex" [union-attr]
228: error: Item "str" of "Union[Path, str]" has no attribute "absolute" [union-attr]
229: error: Item "str" of "Union[Path, str]" has no attribute "absolute" [union-attr]
230: error: Item "str" of "Union[Path, str]" has no attribute "absolute" [union-attr]
231: error: Item "str" of "Union[Path, str]" has no attribute "absolute" [union-attr]
* fix: right types should be valid
* remove new useless `type: ignore`
* docs: add change file
* remove DeprecationWarnings from v1 release
* coverage on unpickling Undefined private attributes
* coverage on undefined in copy, allow Undefined to be pickled unchanged
* fix coverage of model._iter()
* 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`
* fix#2293: Properly encode Decimals without any decimal places.
* doc: Added changelog entry.
* refactor: Move ConstrainedDecimal test from separate file into test_json
* docs: Remove prefix from changelog.
* test: Changed test_con_decimal_encode to @samuelcolvins recommendations
* fix(mypy): handle FilePath and DirectoryPath custom types
closes#2098
* fix(mypy): handle almost all other custom types
* remove mypy overwrite when extra logic is set
* fix unused mypy ignore
* 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
* 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>
* introduce read_only Field constraint
* add changes markdown for read_only constraint
* add readOnly property to json schema generation
* Revert "add readOnly property to json schema generation"
This reverts commit dad3d3e23a7336aa978dcdedc157559ea102fa54.
* change read_only field constraint to allow_mutation
* Update change notes for allow_mutation
Co-authored-by: Samuel Colvin <samcolvin@gmail.com>
* allow field constraints defaults to be not None
* remove unnecessary test after constraint refactor
* push used constraints check back to schema functions
* use tuple item name descriptions instead of indexes
* move get_constraints function to method on FieldInfo
* address code review comments for minor changes
* Apply suggestions from code review
Co-authored-by: Samuel Colvin <samcolvin@gmail.com>
* fix merge conflict
Co-authored-by: Samuel Colvin <samcolvin@gmail.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
* Propagate`ClassVar`s to sub-models
Currently, if a `ClassVar` is defined on a model and re-defined
on a sub-model omitting the `ClassVar` annotation, Pydantic produces an
unrelated error:
NameError: Field name "..." shadows a BaseModel attribute ...
This check was introduced to prevent shadowing Pydantic's own methods
and attributes defined on the `BaseModel` class. Following this change,
class variables (that is, variables annotated with `ClassVar`)
defined on parent models will be inherited by sub-models and
will be overwritable without having to reapply the annotation.
Closes#2061.
* docs: explain how attributes are excluded and when to use `PrivateAttr`
* fix: update `__fields_set__` in `BaseModel.copy(update=…)`
closes#2290
* chore: rewrite to be more explicit
Co-authored-by: Samuel Colvin <samcolvin@gmail.com>
Co-authored-by: Samuel Colvin <samcolvin@gmail.com>
* fix: Change non-existant secrets dir into a warning
* Simplify if condition
Co-authored-by: Eric Jolibois <em.jolibois@gmail.com>
* Reword changelog entry
Co-authored-by: Eric Jolibois <em.jolibois@gmail.com>
Co-authored-by: Samuel Colvin <s@muelcolvin.com>
* 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>
* fix(decorator): align kwargs behaviour with native python
Previously, validate_arguments would strip the value if the keyword
was the same as the target kwargs argument.
Align with Python's behaviour.
* fix: also prevent overwriting variable args
Introduces tests for both, which compare against the native python implementation
Co-authored-by: Eric Jolibois <em.jolibois@gmail.com>
* mention about 'args' in the changelog too
* simplify var_kwargs pop
Co-authored-by: Eric Jolibois <em.jolibois@gmail.com>
Co-authored-by: Eric Jolibois <em.jolibois@gmail.com>