When validating a discriminated union where the union value has been
passed as a Pydantic model instance, we should access the discriminator
field value using the field name and not the field alias (whether one is
set or not).
* Descriptive exception for incorrectly defined validator fields.
Throws a ConfigError wth helpful feedback if a validator is passed incorrectly defined fields.
* Minor grammar correction.
* Expanded example.
* Added test for bad validator decorator fields.
* Added changes .md file.
* Improved wording in error message.
* Test fix.
* Update pydantic/class_validators.py
Encloses expression into a list comprehension.
Co-authored-by: Eric Jolibois <em.jolibois@gmail.com>
* Update pydantic/class_validators.py
Removed some exception verbosity.
Co-authored-by: Eric Jolibois <em.jolibois@gmail.com>
* Update changes/3215-SunsetOrange.md
Removed some changes verbosity.
Co-authored-by: Eric Jolibois <em.jolibois@gmail.com>
* use pytest.raises(.., match=...)
Co-authored-by: Michael <michael.bedford@superloop.com>
Co-authored-by: Eric Jolibois <em.jolibois@gmail.com>
Co-authored-by: Samuel Colvin <s@muelcolvin.com>
* 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>
* Add static checking for default and default_factory
* Describe PR change
* Remove unnecessary booleans default_specified and default_factory_specified
* Add test with default without Field
* Apply suggestions from code review
Co-authored-by: Samuel Colvin <samcolvin@gmail.com>
* Fix tests
* Add handling of Overload types for mypy0.971
* Avoid to use walrus operator
* Support mypy 0.910 for overloaded types
* Increase coverage for mypy plugin
Co-authored-by: Samuel Colvin <samcolvin@gmail.com>
Co-authored-by: Samuel Colvin <s@muelcolvin.com>
* Add ability to use Final in a field type annotation
* Change exc message
* Handle case when field declarated as Field call
* Final field no longer can be class vars
* Remove required assigment for Final field
* Update impl to match description
* Update due to comments
* Create utils.py
I needed non pascal case camel case support
* write tests for new `to_lower_camel()` function
* Create 3463-schlerp.md
* added mention to to_lower_camel()
* changed quotes to single tick
* adding second blank line at end of file.
* again, adding second blank line...
Co-authored-by: Samuel Colvin <s@muelcolvin.com>
* Add annotation to ModelField for use in BaseModel.__signature__
* add changelog
* replace " with '
* Update changes/3413-fix-inspect-signature.md
Co-authored-by: Samuel Colvin <samcolvin@gmail.com>
* fix
Co-authored-by: Samuel Colvin <samcolvin@gmail.com>
Co-authored-by: Samuel Colvin <s@muelcolvin.com>
* Move host regex out of url_regex and inject it afterwards
* Add new host regex with cache variable
* Move url regex strings to separate variables
* Add new postgres url regex with cache variable
* Add tests for failed postgres dns with many hosts
* Add new parts type: HostParts
* Add new slot 'hosts' to PostgreDsn and update init with it
* Add validators to PostgreDsn class.
When multiple hosts are found, all hosts will be store in hosts list. To
keep back compatibility single host will return all data as previously
in main params.
* Add more detail tests to check multi host postgres dsn with attributes
* Add changes description in the file
* Delete usless comments to regex strings because of varable names
* Add missing docstring to postgres_url_regex function
* Update postgre dsn with AnyUrl.slots
* Update AnyUrl.validate_parts to support disabling port validation
* Reuse _host_regex in postgres_url_regex
* Fix typing
* Delete not needed group in regex
* Improve tests by adding parametrize to postgreDsn tests
* Update postgres regex to not validate hosts in it
* Delete duplicated code and use shared validate method
* Move multi host methods into separate class and inherit it in the postgreDsn
* fix tests
* tweaks and re order code
* add a note to docs
Co-authored-by: Samuel Colvin <s@muelcolvin.com>
* Add MongoDsn to pydantic.networks with allowed_schemas and get_default_parts
* Add unit test to MongoDsn and remove default host from default parts becouse it's required by MongoDB protocol
* Fix import issues, follow contributing guide
* Add changes to docs
* Add changes to changelog
* Allow ellipsis on Fields within annotated types
The usecase is TypedDicts, which can't have default values otherwise.
Meaning that adding Optionals to Annotated drops them from the list of
required fields, which the patch fixes.
* Add test for TypedDict required optionals
Clarifies what's required with TypedDicts schemas.
* Add description of changes
* PR feedback
* extra tests as requested
Co-authored-by: Samuel Colvin <s@muelcolvin.com>
* Added support for Rich Repr protocol
* restore line
* Words
* quotes
* Update changes/3099-willmcgugan.md
Adds code to markdown
Co-authored-by: Eric Jolibois <em.jolibois@gmail.com>
* added usage with Rich
Co-authored-by: Eric Jolibois <em.jolibois@gmail.com>
Co-authored-by: Samuel Colvin <s@muelcolvin.com>
* Avoid __dict__ and __weakref__ attributes in AnyUrl and _BaseAddress subclasses
When inheriting from a class with `__slots__`, [child subclasses will get a `__dict__` and `__weakref__` unless they also define `__slots__`](https://docs.python.org/3/reference/datamodel.html#notes-on-using-slots).
```python
from pydantic import AnyUrl, AnyHttpUrl
class AnyOtherHttpUrl(AnyUrl):
allowed_schemes = {'http', 'https'}
__slots__ = ()
print(set(dir(AnyHttpUrl)) - set(dir(AnyUrl)))
#> {'__weakref__', '__dict__'}
print(set(dir(AnyOtherHttpUrl)) - set(dir(AnyUrl)))
#> set()
```
* Update changes/2890-nuno-andre.md
Co-authored-by: Samuel Colvin <samcolvin@gmail.com>
Co-authored-by: Samuel Colvin <s@muelcolvin.com>
* Empty string is a valid JSON-key
Signed-off-by: Sergey Tsaplin <me@sergeytsaplin.com>
* Update changes/4253-sergeytsaplin.md
Co-authored-by: Samuel Colvin <samcolvin@gmail.com>
* has_alias attribute of the ModelField also should be a result of comparison with None
Signed-off-by: Sergey Tsaplin <me@sergeytsaplin.com>
Co-authored-by: Samuel Colvin <samcolvin@gmail.com>
* limit the length of generics._limit_assigned_parameters
* switch to using _limit_cache_size for both
* add change description
* correct `_limit_cache_size` cache
* implemented LimitedDict
* try using UserDict
* try upgrading cython
* stop LimitedDict from inheriting from dict
* separate LimitedDict for typing checking :-(
* fix for __class_getitem__
* Port number is no longer being ignored by HttpUrl.build()
* Update tests/test_networks.py
Co-authored-by: Samuel Colvin <samcolvin@gmail.com>
* Update networks.py
* Update tests/test_networks.py
Co-authored-by: Samuel Colvin <samcolvin@gmail.com>
* Update test_networks.py
* Update test_networks.py
* update change description
Co-authored-by: Samuel Colvin <samcolvin@gmail.com>
Co-authored-by: Samuel Colvin <s@muelcolvin.com>
* Add tests
* Fix the issue
* Add changes file
* Improved convert_generics
* Add default fallback to convert_generics
Improved Annotated and Literal handling
* Fix Cython doesn't support generic types (PEP560)
Watch cython issue cython/cython#2753
Previous implementation can be used after cython 3.0 release
* Add custom type test
* Cosmetic fixes
Co-authored-by: Samuel Colvin <samcolvin@gmail.com>
* Fix typos
* Add SelfReferencing test validation
Add parametrization to
* Fix: parametrization caused test discovery problem
* Better explanation for a test case
* Better assertions for model creation tests
* Rerun CI
Co-authored-by: Samuel Colvin <samcolvin@gmail.com>
* Fix info with in-place modification of field info
* add changes
* add test for 3714
* Update changes/4067-adriangb.md
Co-authored-by: Samuel Colvin <samcolvin@gmail.com>
Co-authored-by: Samuel Colvin <samcolvin@gmail.com>
* fix: `Config.copy_on_model_validation` does a deep copy and not a shallow one
closes#3641
* fix: typo
* use python 3.10 to run fastapi tests
* fix fastapi test call
Co-authored-by: Samuel Colvin <s@muelcolvin.com>
With CentOS 7 Python 3.6, running install from source with pip failed:
sudo podman run -ti --rm centos:7
yum -y update
yum -y install epel-release
yum -y install git python3 python3-devel python3-pip python3-setuptools python3-wheel
git clone https://github.com/samuelcolvin/pydantic.git
cd pydantic
pip3 install .
With following error message:
[root@c99d0585636c pydantic]# pip3 install .
Processing /pydantic
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/pip-91v_ixvz-build/setup.py", line 62, in <module>
history = (THIS_DIR / 'HISTORY.md').read_text()
File "/usr/lib64/python3.6/pathlib.py", line 1197, in read_text
return f.read()
File "/usr/lib64/python3.6/encodings/ascii.py", line 26, in decode
return codecs.ascii_decode(input, self.errors)[0]
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 14648: ordinal not in range(128)
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-91v_ixvz-build/
This PR add the required `read_text(encoding='utf-8')` for `setup.py`.
Signed-off-by: Wong Hoi Sing Edison <hswong3i@pantarei-design.com>
* apply update_forward_refs to json_encoders, fix#3583
* linting
* mypy
* avoid use of ForwardRef with python3.6
* fix ForwardRef usage, take 2
* coverage
* exclude extra field when represent model
* add test code
* fix W293
* add change md
* Update changes/3234-cocolman.md
Co-authored-by: Samuel Colvin <samcolvin@gmail.com>
* Update pydantic/main.py
Co-authored-by: Samuel Colvin <samcolvin@gmail.com>
* Update tests/test_main.py
Co-authored-by: Samuel Colvin <samcolvin@gmail.com>
Co-authored-by: Samuel Colvin <samcolvin@gmail.com>
* Remove `__root__` from BaseModel typing-only attrs
`__root__` is not a class variable nor is it always present.
The switch to `ClassVar` caused type errors to be reported in Pylance/Pyright.
* Add changelog entry
* Add support for removing TypeVarDef in mypy 0.920
* Add changes/3175-christianbundy.md
* type ignore on import
* 🤦
* coverage, again
Co-authored-by: Samuel Colvin <s@muelcolvin.com>