* Fix `AnyUrl.build` doesn't do percent encoding (#3061)
please review
* Use `urllib.parse` instead of custom implementation for percent encoding
* Make `quote_plus` a `stricturl` option
* Add docs for `stricturl(quote_plus=True)`
* Better changes message for #3061
Co-authored-by: Samuel Colvin <samcolvin@gmail.com>
* Fix precent encoding version note to V1.10
Co-authored-by: Samuel Colvin <samcolvin@gmail.com>
* Fix `Building URLs` snippit markdown
Co-authored-by: Samuel Colvin <samcolvin@gmail.com>
* Fix formatting for `docs/examples/types_url_building.py`
* fix docs
Co-authored-by: Samuel Colvin <samcolvin@gmail.com>
Co-authored-by: Samuel Colvin <s@muelcolvin.com>
* feat: Make SecretStr hashable
* docs: Add change documentation
* test: Assert that the hash of SecretStr is an integer value
Co-authored-by: Hasan Ramezani <hasan.r67@gmail.com>
* feat: Make SecretBytes hashable
Co-authored-by: Johannes Rueschel <johannes.rueschel@telekom.de>
Co-authored-by: Hasan Ramezani <hasan.r67@gmail.com>
* Generate docs exampels for Python 3.10 and above
Code quality is not great and main intent here is to show the result.
* Fix docs build on 3.9
* Build docs on 3.10
* What's Python 3.1?
* Create temp dir if not exists
* Refactor and improve imlementetion
* Keep runtime typing in examples
* Revert unrelated formatting changes
* Add changes file
* Allow specifying requirements in examples
* Pin autoflake and pyupgrade
* Add docs/build to Makefile lint/format/mypy
* ignore_missing_imports for ansi2html and devtools
* Add .tmp-projections to .gitignore
* Remove dont-upgrade now when Pattern is supported
* Update postponed evaluation examples
Co-authored-by: Samuel Colvin <s@muelcolvin.com>
* Initial implmenetation of ConstrainedDate, condate, with tests and docs
* Attempt at fixing hypothesis tests for ConstrainedDate. Suspect still not working
* removed forgotten breakpoint() :(
* suggested changes to pydantic/_hypothesis_plugin.py for condate etc
Co-authored-by: Zac Hatfield-Dodds <zac.hatfield.dodds@gmail.com>
* - fixed import for hypothesis tests
* - linting fixes only
* - more fixes for linting
* changes following review by samuelcolvin 2022-08-08. Will rebase next
* - added changes to changes file
* fixed changes file filename to PR #3740
* additional changes requested by samuelcolvin 2022-08-11: add test for schema_json, add hypothesis test, etc
* make test_json_schema compare to a dictionary rather than json string
* added test_date_constrained_types to test_schema
* rewrite tests
Co-authored-by: Zac Hatfield-Dodds <zac.hatfield.dodds@gmail.com>
Co-authored-by: Samuel Colvin <s@muelcolvin.com>
* generate history from changes, uprev
* Pydantic V2 blog (#4218)
* first draft of pydantic V2 blog
* more blog
* blog rendering and formatting
* more section
* completing conversion table
* prompt build
* reviewing blog post
* more reviewing and extending
* recommendations from @Rabscuttler and @PrettyWood
* add implementation details and more suggestions
* comment about breaking changes
* convert namespae to table, more removals
* Apply suggestions from code review by @tiangolo
Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
* feedback from @tiangolo's review
* changes from @adriangb's review
* Apply suggestions from code review
Co-authored-by: Zac Hatfield-Dodds <zac.hatfield.dodds@gmail.com>
* convert namespace info to psuedo-code
* rename property, remove schema_json()
* adding validation context
* remove 'model_schema_json', take 2
* more tweaks while reviewing
* comment about pypy and tagged unions
* add thanks :prey:, prepare for release
* suggestions from @PrettyWood
* suggestions from @PrettyWood, model_dump_json comment
Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
Co-authored-by: Zac Hatfield-Dodds <zac.hatfield.dodds@gmail.com>
* comments mostly from @PrettyWood (#4226)
* comments mostly from @PrettyWood
* add updated comment
* fix pre-commit
* allow for shallow copies (#4093)
* allow for shallow copies
* Add changes file
* tweak change
* update for comments
* rename attr
* use single quotes
* bump ci
* add warning if not a string, switch to string literals
* fix linting, prompt ci
* fix ci
* extend and fix tests
* change default to "shallow"
Co-authored-by: Samuel Colvin <s@muelcolvin.com>
* uprev and prepare for release
* linting
Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
Co-authored-by: Zac Hatfield-Dodds <zac.hatfield.dodds@gmail.com>
Co-authored-by: Tim Paine <t.paine154@gmail.com>
* Allow BaseModel to have fields of type Type
* update
* minor update
* update tests
* update
* fix type
* update
* Update changes/4051-aminalaee.md
Co-authored-by: Samuel Colvin <samcolvin@gmail.com>
* Fix a bug where BaseModel.construct would not appropriately respect field aliases
* Perhaps do not raise on construct and just apply the fix
* Fix quotes and remove check on allow_population_by_field_name
* Fix lint
* Fix lint, remove bad arg
* Black formatted
* Mmmm black formatter and single quotes linting, what a world
* Added change file
* PR feedback
Co-authored-by: Kyle Amos <kamos@seatgeek.com>
* Teach mypy plugin that validator methods are classmethods
For your consideration: a patch which implements the suggestion I made here:
https://github.com/samuelcolvin/pydantic/discussions/4101
Briefly: pydantic automatically wraps validator methods using
`@classmethod`. Hence the first argument to a user-provided validator
should be `cls`. But mypy doesn't know this: it analyses validator
methods like any other regular method, believing the first parameter
`cls` to be a model instance (usually denoted self).
This means that if one annotates `cls` as `Type[...]` then mypy
believes raises an error:
error: The erased type of self "Type[temp.Model]" is not a supertype of its class "temp.Model"
I concede that this is an extremely niche thing. The only tangible
end-user benefit I can think of is that it'll stop you from calling
instance methods in a validator.
----
I haven't written a mypy plugin before, so this is a bit of a
hack-until-it-works. But it was more straightforward than I expected to
get something working!
* changelog
* Add failure test
* Add .venv/ to .gitignore
* Allow typecheckers to infer Json inner type
* Fix and improve mypy tests
* Add type tests
* Add Json[Any] case to schema test
* Update example in docs
* Add changes file
* Use <3.9 compatible annotations for tests
* feat: pass config to create_model_from_namedtuple
* feat: tests for arbitrary_types_allowed in NamedTuple fields
* misc: add changelog file for the PR
* feat: add to upper function for strings and bytes
* docs(changes): add message for change
* fix: add constr upper on types
* fix: add constr upper on types
* feat: add examples and doc usage
* test: add test to upper for types
* chore: apply suggestions from code review
Co-authored-by: Hasan Ramezani <hasan.r67@gmail.com>
* chore(docs): reorder `anystr_upper` to under `anystr_lower`
* fix(test): adjust parametrizes to constrained bytes upper
* refactor: use pytest parametrize for unify test constrained str upper
* refactor: use pytest parametrize for unify test constrained str lower
* refactor(test): use pytest parametrize for unify test any str upper
* refactor(test): use pytest parametrize for unify test any str lower
* refactor(test): use pytest parametrize for unify test constrained bytes lower
* refactor(test): use pytest parametrize for unify test any str strip whitespace
* refactor(test): change test signatures to improve readability
Co-authored-by: Hasan Ramezani <hasan.r67@gmail.com>
The mypy plugin would previously incorrectly determine that a field was
not required in a few scenarios where the field really is required. This
specifically affected cases when the `Field()` function is used, where
the plugin assumed that the first argument would always be `default`.
This changes the code to examine each argument more closely, and it now
properly handles several more scenarios where the default is explicitly
named or when the default_factory named argument is used.
* 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>
* 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>