* support overwriting dunder attributes of `BaseModel` instances
closes#3777
* suggestion from @adriangb
Co-authored-by: Samuel Colvin <s@muelcolvin.com>
* Add CockroachDsn type
The CockroachDsn type supports the following dialects: cockroachdb,
cockroachdb+psycopg2 and cockroachdb+asyncpg. It's meant to be used in
conjunction with the cockroachdb sqlalchemy dialect, more information
can be found here:
https://github.com/cockroachdb/sqlalchemy-cockroachdb
* tweak change log
Co-authored-by: Samuel Colvin <s@muelcolvin.com>
* updates to description of the fields option.
Update of the fields option for config to reflect the fact that it is not actually equivalent to the Field class, as I was having troubles understanting ehy I couldn't set default or default_factory.
* corrected typo
* correction
* fix typo
Co-authored-by: Samuel Colvin <s@muelcolvin.com>
* changed timedelta_isoformat in pydantic/json.py to produce ISO 8601 compliant string even for negative values
* added tests to verify correct serialization of negative time deltas
Co-authored-by: Josef <sorry.i-keep@it.private>
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>
* improved issue template and more
* tweak wording
* more tweaks
* more tweaks
* add Affected Components
* Update .github/ISSUE_TEMPLATE/bug.yml
Co-authored-by: Hasan Ramezani <hasan.r67@gmail.com>
Co-authored-by: Hasan Ramezani <hasan.r67@gmail.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>