* Remove Cython
* fix CI
* fix coverage
* fix tests
* switching to pypyroject.toml
* pre-commit all and use pre-commit for linting
* no mypy tests on macos and windows on ci, use flake8-pyproject
* fix docs and tests CI
* check build is working
* drop pytest-cov
* window and macos ci with 3.11, reduce filtering
* use pip-tools to pin all dependencies
* fix docs and fastapi tests
* fix test deps for 3.7
* no cache on tests job
* revert fastapi changes, fix coverage
* fix mypy coverage
* test with older mypy
* dotenv not required for mypy tests
* split testing requirements std and extra
* typo
* @PrettyWood comments
* correct branch name
* mypy python_version and pr template
* ✨ Add JSON-compatible float constraints for NaN and Inf
* switching to a single "allow_inf_nan"
* fix tests
* add change and docs
* add allow_inf_nan to Config
Co-authored-by: Samuel Colvin <s@muelcolvin.com>
* 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>
* 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>
* 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>
* 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>
* 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
* Add RabbitmqDsn
Will update once finished - haven't looked at the CONTRIB yet. Want to test locally to see if it works.
* added tests; added to docs
* added changes
* fixed import in networks.py
* fixed linting issues; fixed __init__.py import issue
* sorted imports
* added trailing comma on imports
* Merge master
* Change class name from RabbitmqDsn to RabbitMqDsn
* Format code
* Rename change file and prettify content
* Fix RabbitMQ name on documentation
* Add a trivial test
* Address Samuel and Nuno's comments
* Refactor AMQP tests according to Redis tests style
* Update docs/examples/settings_main.py
* cleanup
Co-authored-by: Thomas <thomas@9bitbyte.com>
Co-authored-by: Thomas Crha <tom.crha@dragonflytechnologies.com>
Co-authored-by: Samuel Colvin <s@muelcolvin.com>
* Add unique items validation to constrained list
* add unique_items to field and schema
add failover for unhashable types
check keyword value to call the validator
add some tests
* update unique_items validation
Co-authored-by: Nuno André Novo <nuno.novo@forensic-security.com>
Co-authored-by: Samuel Colvin <s@muelcolvin.com>
* add `FileUrl` type for `file://` schemes
Also add a `host_required` parameter, True by default,
False in `FileUrl` and `RedisDsn`.
* chore: useless extra in assert statement
Co-authored-by: PrettyWood <em.jolibois@gmail.com>
* Added suport to postgresql async driver
* Added postgres+asyncpg in the doc.
* Added changes file
* Added postgresql+pg8000 schema
* ran make format
* Update docs/usage/types.md
Co-authored-by: Stephen Brown II <Stephen.Brown2@gmail.com>
* Changed from schema to scheme
Co-authored-by: Eric Jolibois <em.jolibois@gmail.com>
* fixed typo scheme
* fixed merge schema
* changed to one line description
Co-authored-by: Eric Jolibois <em.jolibois@gmail.com>
* added others DBAPI dialects.
* Added two # by PrettyWood
Co-authored-by: Eric Jolibois <em.jolibois@gmail.com>
* fix typo by PrettyWood
Co-authored-by: Eric Jolibois <em.jolibois@gmail.com>
* Fixed typo by PrettyWood
Co-authored-by: Eric Jolibois <em.jolibois@gmail.com>
* added postgresql+psycopg2 in changes dir
* Fixed typo by @samuelcolvin
Co-authored-by: Samuel Colvin <samcolvin@gmail.com>
* docs: fix typo
* chore: sort alphabetically
Co-authored-by: Fernando Ike <fernando.ike@maburix.com>
Co-authored-by: Stephen Brown II <Stephen.Brown2@gmail.com>
Co-authored-by: Eric Jolibois <em.jolibois@gmail.com>
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
* feat: add support for `NamedTuple` and `TypedDict` types
* support `total=False`
* tests: fix ci with python < 3.8 without typing-extensions
* chore: improve mypy
* chore: @samuelcolvin remarks
* refactor: move tests in dedicated file
* docs: add annotated types section with examples
* feat: support properly required and optional fields
* chore(deps-dev): bump typing_extensions
* docs: add a note for `typing_extensions`
* chore: update message to be more accurate
* feat: pass down config to created models
* feat: add util methods to create model from TypedDict or NamedTuple
* refactor: rename into typeddict and namedtuple
* test: add utils tests
* chore: fix lint
* chore: improve test
* refactor: rename utils to match the rest
* chore: update change
* docs: add section for create_model_from_{namedtuple,typeddict}
* refactor: rename typed_dict/named_tuple
* feat: support schema with TypedDict
* feat: support schema for NamedTuple
* feat: add json support for NamedTuple
* chore: rewording
* refactor: use parse_obj
* fix: add check for max items in tuple
* docs: separate typing.NamedTuple and collections.namedtuple
* added anystr_lower field to config
* updated docs with any anystr_lower config property
* updated changes folder with markdown describing new change
* added anystr to _validators list under bytes type
* added unit tests for anystr_lower config
* Update pydantic/validators.py
Fix wrong method used in cosntr_lower
Co-authored-by: Eric Jolibois <em.jolibois@gmail.com>
* added lower_str to conbytes and constr functions
* Update changes/2134-tayoogunbiyi.md
Co-authored-by: Samuel Colvin <samcolvin@gmail.com>
* renamed conbytes & constr paramater name
* updated change markdown
* added docs for args to constr and conbytes
* added examples to showing to_lower functionality in conbytes & constr
* added better description for curtail_length
* removed unessary whitespace, added default and types in docs
* Update changes/2134-tayoogunbiyi.md
Co-authored-by: Eric Jolibois <em.jolibois@gmail.com>
* added single whitespace to arguments list under constr & conbytes
Co-authored-by: Eric Jolibois <em.jolibois@gmail.com>
Co-authored-by: Samuel Colvin <samcolvin@gmail.com>
Co-authored-by: Samuel Colvin <s@muelcolvin.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
* 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>
* Parse timezone information in time str
* Add description of change fixing issue 1744
* Guard against TZ over 24 hours
* Parse timezone information in time str
* Datetime and time TZ parsed in separate fn
* Sharpen annotation, many return statements
* Fix mypy errors raised on datetime_parse
* fix type hints
* update docs and correct types
Co-authored-by: Samuel Colvin <s@muelcolvin.com>
* feat(field): add Enum type support
closes#1735
* test: add extra cases and rename to be more explicit
* refactor: rename enum_validator
* feat: add Enum and IntEnum types support
* docs: add new types
* chore: update change message
* make secret types idempotent
* remove idempotent from secret types example.
add note to docs for idempotently creating secret types.
use isinstance for comparing when creating secret types idempotently.
add assert for idempotent secret types test.
* tweaks
Co-authored-by: Lasse Gravesen <lasse.gravesen@falcon.io>
Co-authored-by: Samuel Colvin <s@muelcolvin.com>
* ✨ Add support for generics with __get_validators__
* ✅ Add tests for Generics with __get_validators__
* 📝 Add change note
* ✨ Add support for Generic fields with validation of sub-types
* 📝 Add docs for arbitrary generic types
* ✅ Add tests for generic sub-type validation
* 📝 Update change note. Generic support is not so "basic" now
* 📝 Update docs with code review
* ♻️ Update fields module with code review changes
* ✅ Update tests from code review
* 📝 Update example for generics, try to simplify and explain better
* tweak docs example
Co-authored-by: Samuel Colvin <samcolvin@gmail.com>
* ✨ Implement support for infinite generators with Iterable
* ✅ Add tests for infinite generators
* 🎨 Fix format
* 📝 Add docs for infinite generators
* 📝 Add changes file
* ✨ Store sub_field with original type parameter to allow custom validation
* 📝 Add example for validating first value in infinite generators
* 🔥 Remove unused import in example
* ✅ Add test for infinite generator with first-value validation
* ♻️ Update fields with code review
* 📝 Update example from code review
* 📝 Update docs and format from code review
* Implement Optional required, when creating a ModelField(required=True), make it persist
* Add test for nullable required
* Improve formatting of Undefined custom object
* Refactor field infer/creation with Undefined to make it idempotent
Needed for when _type_analysis is re-run in Generics
* Add PR changes
* Increment/update tests with code review
* Update/refactor Undefined implementation with code review
* Fix BoolUndefined as string type for mypy, not runtime
* Add docs about required Optional
* Add explicit tests for Any
* Apply code review requested changes
* move tests out of test_validators.py