202 Commits

Author SHA1 Message Date
⬢ Samuel Colvin ef8f9fe51b Uprev all dependencies (#4955)
* Uprev all dependencies

* use ruff instead of flake8 for docs examples linting
2023-01-15 09:57:09 -08:00
florianfischer91 f55515820a Rename model methods (#4889)
* renaming .json -> .model_dump_json

* renaming .dict -> .model_dump

* renaming .__fields__ -> .model_fields

* renaming .schema -> .model_json_schema

* renaming .construct -> .model_construct

* renaming .parse_obj -> .model_validate

* make linters happy

* add changes md-file

Co-authored-by: Samuel Colvin <s@muelcolvin.com>
2023-01-05 11:30:44 +00:00
Jim Kring 08f7cf63c9 config variable to raise UserWarning if model not fully defined (#4882)
* added config var warn_on_undefined_types
raises a UserWarning if model not fully defined and will need rebuild

* black formatting

* use | instead of Optional[]

* suppress undefined types warning in existing tests

* ran pre-commit to fix linting

* changed to use Optional since | failing in CI

* changes following initial code review

* added some preliminary documentation

* fix linting

* fixed linting

* fixed linting

* assert model partially built when suppressing warn

* moved check for ForwardRef into existing for loop

* change assertion to dict instead of json

* cleanup of undefined_types_warning tests and docs

* Update docs/examples/types_undefined_warning.py

* Update docs/examples/types_undefined_warning.py

* fix EOL (trim trailing whitespace) lint error

Co-authored-by: Samuel Colvin <s@muelcolvin.com>
2023-01-04 19:23:39 +00:00
kgolawski f9e8c64f12 Fix code typo in docs (#4776) 2022-11-22 13:33:48 +01:00
Pierre Bonneau 21b8e22214 Renaming BaseModel (#4758)
Hello

BaseModel is an import from pydantic.
Using that same name for the Base from sqlachemy can be misleading, and not aligned to the other examples.

I therefore suggest to use the same naming that the other example.

Pierre
2022-11-17 10:01:56 +00:00
Samuel Colvin 594effa279 Switching to pydantic_core (#4516)
* working on core schema generation

* adapting main.py

* getting tests to run

* fix tests

* disable pyright, fix mypy

* moving to class-based model generation

* working on validators

* change how models are created

* start fixing test_main.py

* fixing mypy

* SelfType

* recursive models working, more tests fixed

* fix tests on <3.10

* get docs build to pass

* starting to cleanup types.py

* starting works on custom types

* working on using annotated-types

* using annoated types for constraints

* lots of cleanup, fixing network tests

* network tests passing 🎉

* working on types

* working on types and cleanup

* fixing UUID type, restructing again

* more types and newer pydantic-core

* working on Iterable

* more test_types tests

* support newer pydantic-core, fixing more test_types.py

* working through more test_types.py

* test_types.py at last passing locally 🎉

* fixing more tests in test_types.py

* fix datetime_parse tests and linting

* get tests running again, rename to test_datetime.py

* renaming internal modules

* working through mypy errors

* fixing mypy

* refactoring _generate_schema.py

* test_main.py passing

* uprev deps

* fix conftest and linting?

* importing Annotated

* ltining

* import Annotated from typing_extensions

* fixing 3.7 compatibility

* fixing tests on 3.9

* fix linting

* fixing SecretField and 3.9 tests

* customising get_type_hints

* ignore warnings on 3.11

* spliting repr out of utils

* removing unused bits of _repr, fix tests for 3.7

* more cleanup, removing many type aliases

* clean up repr

* support namedtuples and typeddicts

* test is_union

* removing errors, uprev pydantic-core

* fix tests on 3.8

* fixing private attributes and model_post_init

* renaming and cleanup

* remove unnecessary PydanticMetadata inheritance

* fixing forward refs and mypy tests

* fix signatures, change how xfail works

* revert mypy tests to 3.7 syntax

* correct model title

* try to fix tests

* fixing ClassVar forward refs

* uprev pydantic-core, new error format

* add "force" argument to model_rebuild

* Apply suggestions from code review

Suggestions from @tiangolo and @hramezani 🙏

Co-authored-by: Hasan Ramezani <hasan.r67@gmail.com>
Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>

* more suggestions from @tiangolo

* extra -> json_schema_extra on Field

Co-authored-by: Hasan Ramezani <hasan.r67@gmail.com>
Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
2022-11-02 12:01:17 +00:00
Rémy HUBSCHER 0a6e413866 Add missing typing to example (#4596)
* Add missing typing to example

* Update example typing.
2022-10-10 13:36:03 +02:00
Samuel Colvin 85e4596958 Move settings to pydantic-settings (#4492)
* Move settings to pydantic-settings

* fix docs, remove dotenv

* fix coverage

* removing unused test fixture
2022-09-07 13:05:51 +01:00
Samuel Colvin a4367c1c58 Revert percent encoding in URLs. (#4470)
* Revert "Fix `AnyUrl.build` doesn't do percent encoding (#3061) (#4224)"

This reverts commit e34ff9255f.

* change and warning
2022-09-05 11:02:43 +01:00
Anthony Miyaguchi fe7c9da6c1 Fix #1458 - Allow for custom parsing of environment variables via parse_env_var in Config object (#4406)
* Fix #1458 - Allow for custom parsing of environment variables via env_parse

* Add docs for env_parse usage

* Add changes file for #3977

* fixup: remove stray print statement

* Revert env_parse property on field

* Add parse_env_var classmethod in nested Config

* Update documentation for parse_env_var

* Update changes file.

* fixup: linting in example

* Rebase and remove quotes around imported example

* fix example

* my suggestions

* remove unnecessary Field(env_parse=_parse_custom_dict)

Co-authored-by: Samuel Colvin <s@muelcolvin.com>
2022-08-22 16:06:14 +00:00
Fares Ahmed e34ff9255f Fix AnyUrl.build doesn't do percent encoding (#3061) (#4224)
* 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>
2022-08-19 09:20:20 +00:00
Samuel Colvin 2f883b9509 fix pattern matching version, ref #3921 (#4384) 2022-08-16 22:29:59 +01:00
rafael 7344374dd0 BaseModel: Document and test structural pattern matching (#3921)
* BaseModel: Add __match_args__ attribute to namespace

* changelog

* amend docs

* add tests

* Update changes/3920-irgolic.md

Co-authored-by: Samuel Colvin <samcolvin@gmail.com>

* Update .github/workflows/ci.yml

Co-authored-by: Samuel Colvin <samcolvin@gmail.com>

* rename test_match => test_structural_pattern_matching

* pytest.skip => pytest.mark.skipif

* Revert "BaseModel: Add __match_args__ attribute to namespace"

This reverts commit 79367356fddac90b047b10620dc895425ec25b40.

* adjust tests for kwarg only structural pattern matching

* adjust docs for kwarg only pattern matching

* changes: Support => Document

* fix docs?

Co-authored-by: Samuel Colvin <samcolvin@gmail.com>
2022-08-16 08:47:17 +02:00
Arseny Boykov c24d33e5f1 Generate docs exampels for Python 3.10 and above (#4339)
* 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>
2022-08-14 17:21:53 +01:00
Samuel Colvin 5c8942bdd4 Revert "Add nested json encoding (#3941)" (#4367)
This reverts commit b42fae081c.
2022-08-12 11:08:33 +01:00
Hasan Ramezani 697459a73d Change path in validation_decorator_types example to a relative path (#4341)
* Change path in validation_decorator_types example to a relative path

* make the example a little clearer

Co-authored-by: Samuel Colvin <s@muelcolvin.com>
2022-08-09 11:12:05 +00:00
Arseny Boykov 0500610ec5 Typecheck Json inner type (#4332)
* 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
2022-08-09 11:49:27 +01:00
Gustavo Satheler d90def3c4e Add to upper function for strings and bytes (#4165)
* 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>
2022-08-08 17:06:00 +01:00
Lily Wang b42fae081c Add nested json encoding (#3941)
* add nested json encoding

* fix timezones

* add changes doc

* split tests and rename example

* Update changes/3941-lilyminium.md

Co-authored-by: Samuel Colvin <samcolvin@gmail.com>

* split tests into functions

Co-authored-by: Samuel Colvin <samcolvin@gmail.com>
Co-authored-by: Samuel Colvin <s@muelcolvin.com>
2022-08-08 15:46:51 +00:00
Mateo Aguirre Duque 7431683e88 Alias support in decorator validate_arguments (#3019)
* 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>
2022-08-08 13:33:51 +01:00
Eric Jolibois 576e4a3a8d refactor: change pydantic dataclass decorator (#2557)
* refactor: rewrite the whole pydantic dataclass logic

* test: add tests for issue 2162

* test: add tests for issue 2383

* test: add tests for issue 2398

* test: add tests for issue 2424

* test: add tests for issue 2541

* test: add tests for issue 2555

* refactor: polish

* change default and support 3.6

* fix coverage

* fix mypy and text

* typos

* test: add tests for issue 2594

* fix: forward doc for schema description

* add change

* chore: small changes from review

* refactor: avoid extra __pydantic_run_validation__ parameter

* small tweaks

* remove wrapper

* support 3.6

* fix: mypy

* rewrite doc

* add docs

* wrapper is removed now

* a bit more docs

* code review

* faster dict update

* add test for issue 3162

* add test for issue 3011

* feat: add `Config.post_init_after_validation`

* allow config via dict

* fix cython and TypedDict

* chore: typo

* move `compiled` in `version.py`

* refactor: switch from `Config.post_init_after_validation` to \'post_init_call`

* add dataclass isinstance support

* avoid multi paragraphs in change file

* feat: support `Config.extra`

* refactor: simplify a bit code

* refactor: avoid creating useless functions

* refactor: simplify `is_builtin_dataclass`

* support extra in post_init

* docs: add warning on config extra

* fix #3713 compatibility

* update docs

Co-authored-by: Samuel Colvin <s@muelcolvin.com>
2022-08-04 12:06:54 +01:00
Hernán Alarcón eadfdbdbde Fix mypy error in models_recursive.py example. (#3995) 2022-07-21 08:52:44 +02:00
Eric Jolibois edad0dbc46 fix: keep old behaviour of json() by default (#3542)
* fix: handle basemodel fallback for custom encoders

* put back old behaviour and add to_dict

* typo

Co-authored-by: Christian Bundy <christianbundy@fraction.io>

Co-authored-by: Christian Bundy <christianbundy@fraction.io>
2021-12-24 13:14:13 +00:00
Eric Jolibois 81b13ff3b4 fix: rename schema util into schema_of (#3547) 2021-12-22 19:42:56 +00:00
Mark Trifonov be246701c5 Nested env (#3159)
* Environment names for complex types #2304

* nested env disabled by default

* cleanup

* nested env settings: simplified and mypy fixes

* nested env settings: config, test, doc

* nested env settings: changes file

* nested env settings: cleanup

* Apply suggestions from code review

Co-authored-by: Samuel Colvin <samcolvin@gmail.com>

* Apply suggested changes from code review

* lint fix

* changes from code review

* simplify explosing env vars

* linting

Co-authored-by: Mark Trifonov <>
Co-authored-by: Samuel Colvin <samcolvin@gmail.com>
Co-authored-by: Samuel Colvin <s@muelcolvin.com>
2021-12-18 20:56:14 +00:00
Jaakko Moisio 63337fbadc Add optional field argument to __modify_schema__() (#3434)
Co-authored-by: Samuel Colvin <s@muelcolvin.com>
2021-12-18 20:55:22 +00:00
Marcelo Trylesinski 7eaa582980 Add AmqpDsn class (#3254)
* 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>
2021-12-18 20:40:16 +00:00
Eric Jolibois c834f3419d Support discriminated union (#2336)
* feat: add discriminated union

* feat: add OpenAPI spec schema

* test: add basic example for generated schema

* test: add validation tests

* docs: add basic documentation

* fix: support ForwardRef

* test: add ForwardRef case

* fix: false positive lint error

https://github.com/PyCQA/pyflakes/pull/600

* improve error

* add schema/schema_json utils

* fix tests after merge

* refactor: add `discriminator` attribute to `FieldInfo`

* refactor: @cybojenix remarks

* fix schema with forward ref

* start nested

* feat: add allowed values in error message

* fix wrong check

Same example with

```
class FooDomainA(BaseModel):
    __root__: Union[FooDomainAA, FooDomainAB]
```

(without a discriminator)
should obviously be valid

* test: add nested examples

* remove uncovered code as we don't need it

* docs: add nested example

* fix: support properly Annotated Field syntax

* support naked annotated

* fix: handle TypeError

* make error loc more explicit

* fix behaviour with basemodel instance as value

* support schema for dataclasses

* tweak examples

* refactor: context manager just around code that fails

* refactor: add docstring + tweak on `get_sub_types`

* refactor: move `get_discriminator_values` in `utils.py`

* refactor: create `MissingDiscriminator` and `InvalidDiscriminator`

* refactor: move logic in `_validate_discriminated_union`

* refactor: remove `DiscriminatedUnionConfig`

* docs: schema/schema_json

* tests: add tests with other `Literal` types

* update 3.10

* add schema docstring

* weird bug on 3.8 with `Literal[None]`

* bump to view docs & coverage

* bump to prompt tests

* move tests in dedicated file

* chore: rewording

* refactor: replace property by direct slot

* refactor: faster check

* refactor: missing discriminator

* refactor: change error to ConfigError

* refactor: use display_as_type

* fix: mypy

* fix: duplicate

* feat: handle alias

* feat: handle nested unions

* tweak first example

Co-authored-by: Samuel Colvin <s@muelcolvin.com>
2021-12-18 16:31:35 +00:00
Michael Rios 043d16bcf8 Update validator function name in examples to show that value must b… (#3327)
* Update validator function name in  examples to show that value must be bar vs must contain a space

* Add md file in
2021-12-08 23:17:08 +00:00
Eric Jolibois 458f257dcb feat: make JSON serialization of referenced pydantic models possible (#2650)
* feat: make JSON serialization of referenced pydantic models possible

* add docs

* chore: @samuelcolvin remarks
2021-12-07 22:01:11 +00:00
Eric Jolibois c38c463137 feat: add Config.smart_union option (#2092)
* feat: add `Config.smart_union` to prevent coercion in `Union` if possible

* docs: write some documentation

* Update docs/usage/model_config.md

Thanks @djpugh

Co-authored-by: David J Pugh <6003255+djpugh@users.noreply.github.com>

* improve doc

* support 3.10

* improve smart_union

* Update docs/usage/types.md

Co-authored-by: David J Pugh <6003255+djpugh@users.noreply.github.com>

* put new sentence inside warning block

* docs: reorder

* rename is_union_origin into is_union

* inverse and condition for perf

* fix doc

Co-authored-by: David J Pugh <6003255+djpugh@users.noreply.github.com>
2021-12-07 21:58:52 +00:00
q0w 4af50043f1 docs: Print name classes for __concrete_name__ example (#3470)
* Print name classes

* use `repr` to display class name

Co-authored-by: Eric Jolibois <em.jolibois@gmail.com>
2021-12-07 10:45:39 +01:00
Yurii Karabas 415eb54f96 Try to evaluate forward refs after model created (#2588)
* Try to evaluate forward refs after model created

* Upadate docs and remove code duplication

* Update changes/2588-uriyyo.md

Co-authored-by: Eric Jolibois <em.jolibois@gmail.com>

* Update docs/usage/postponed_annotations.md

Co-authored-by: Eric Jolibois <em.jolibois@gmail.com>

* Remove unused import

Co-authored-by: Eric Jolibois <em.jolibois@gmail.com>
2021-12-05 14:20:48 +00:00
Nuno André b718e8e626 Add GetterDict example (#2463)
* Add GetterDict example

* Update docs/usage/models.md

Co-authored-by: Samuel Colvin <samcolvin@gmail.com>

Co-authored-by: Samuel Colvin <samcolvin@gmail.com>
2021-05-12 15:25:17 +01:00
Davis Kirkendall db697cc799 Add exclude as field parameter (#2231)
* Add exclude/include as field parameters

- Add "exclude" / "include" as a field parameter so that it can be
  configured using model config (or fields) instead of purely at
  `.dict` / `.json` export time.
- Unify merging logic of advanced include/exclude fields
- Add tests for merging logic and field/config exclude/include params
- Closes #660

* Precompute include/exclude fields for class

* Increase test coverage
* Remove (now) redundant type checks in Model._iter: New
  exclusion/inclusion algorithms guarantee that no sets are passed further down.

* Add docs for advanced field level exclude/include settings

* Minimal optimization for simple exclude/include export

Running benchmarks this vs. master is at:

this: pydantic best=33.225μs/iter avg=33.940μs/iter stdev=1.120μs/iter version=1.7.3
master: pydantic best=32.901μs/iter avg=33.276μs/iter stdev=0.242μs/iter version=1.7.3

* Apply review comments on exclude/enclude field arguments

* Fix/simplify type annotations
* Allow both ``True`` and ``Ellipsis`` to be used to indicate full field
  exclusion
* Reenable hypothesis plugin (removed by mistake)
* Update advanced include/include docs to use ``True`` instead of ``...``

* Move field info exclude/include updates into FieldInfo class

This way, the model field object does not need to concern itself with
dealing with field into specific fields.
(Same was done for alias in a previous commit).

* remove double back tick in markdown.

Co-authored-by: Samuel Colvin <samcolvin@gmail.com>
2021-05-01 16:45:37 +01:00
Eric Jolibois 3ec35590f1 Support Field in dataclass + 'metadata' kwarg of dataclasses.field (#2384)
* 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`
2021-02-25 20:04:16 +00:00
Tom Cobb 3f849a368f Support Field(default_factory) in validate_arguments (#2176)
* Support Field(default_factory) in validate_arguments

* Added docs for validate_arguments with Field
2021-02-23 12:07:11 +00:00
Arseny Boykov ce67660d2f Allow to configure models through class kwargs (#2356)
* 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>
2021-02-22 17:10:04 +00:00
Samuel Colvin b7a8ef25c6 fix coverage and make typing-extensions a required dependency (#2368)
* fixing coverage by simplifying Annotated import logic, fix #2367

* avoid checking against annotated if it's None

* make typing-extensions required WIP

* more making typing-extensions required

* fix docs and get_origin for python 3.6

* fix mypy test

* fix docs

* update docs, cleanup and add change

* clean docs/examples/schema_annotated.py

* move AnnotatedTypeNames
2021-02-17 19:17:30 +00:00
Jacob Hayes b742c6f527 Support Annotated type hints and extracting Field from Annotated (#2147)
* 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
2021-02-13 16:13:21 +00:00
Arthur Pastel 33c5a4dc34 Add merged json_encoders inheritance (#2064)
* Implement merged json_encoders inheritance

* json_encoders inheritance documentation
2021-02-13 15:56:34 +00:00
Anthony King b4d1ada004 fix(decorator): detect when a duplicate argument is passed in (#2250)
* 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>
2021-02-13 11:06:12 +00:00
Eric Jolibois c314f5a909 feat: add support for NamedTuple and TypedDict types (#2216)
* 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
2021-02-13 10:05:57 +00:00
Eric Jolibois f11b3ae313 feat: avoid reconstructing models used as fields of another model on validation (#2193)
* feat: avoid reconstructing models used as fields of another model on validation

closes #265
closes #1837

* docs: add section to change config

* change default value to avoid breaking change

* refactor: only suggest custom BaseModel approach
2021-02-12 13:04:52 +00:00
Eyitayo Ogunbiyi 61b45340e7 Feature/add anystr lower to config (#2183)
* 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>
2021-02-12 12:28:08 +00:00
Thomas Berdy 1155de82b9 feat: Add the ability to add extra settings sources (#2107)
* feat: Add the ability to add extra settings sources

* doc: Document "customise settings sources" feature

* tests: Add missing test and add change file

* Update changes/2107-kozlek.md

Co-authored-by: Eric Jolibois <em.jolibois@gmail.com>

* improve docs for settings customise_sources

* fix docs building

* fix test :-(

Co-authored-by: Thomas Berdy <thomas.berdy@outlook.com>
Co-authored-by: Eric Jolibois <em.jolibois@gmail.com>
Co-authored-by: Samuel Colvin <s@muelcolvin.com>
2021-02-11 16:55:40 +00:00
Zac Hatfield-Dodds 771b0d3d92 Add a Hypothesis plugin (#2097)
* Configure Hypothesis

* Hypothesis plugin docs

* Add Hypothesis plugin

Co-authored-by: Samuel Colvin <s@muelcolvin.com>
2021-02-11 12:33:11 +00:00
Eric Jolibois 8bad7bc911 feat: add validate method on function to validate input without calling it (#2128)
* feat: add `validate` method on function to validate input without calling it

* docs: add documentation

* chore: add change file
2020-12-31 17:45:51 +00:00
Mykola Solodukha aacf592040 Add rediss (Redis over SSL) protocol to RedisDsn (#1911)
* Add `rediss` (Redis over SSL) protocol to `RedisDsn`

* Update docs

* Update changes history

* Fix typo in `changes/1911-TrDex.md`

Co-authored-by: PrettyWood <em.jolibois@gmail.com>

* Bump black from 19.10b0 to 20.8b1 (#1909)

* Bump black from 19.10b0 to 20.8b1

Bumps [black](https://github.com/psf/black) from 19.10b0 to 20.8b1.
- [Release notes](https://github.com/psf/black/releases)
- [Changelog](https://github.com/psf/black/blob/master/CHANGES.md)
- [Commits](https://github.com/psf/black/commits)

Signed-off-by: dependabot[bot] <support@github.com>

* fix: run `make format`

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: PrettyWood <em.jolibois@gmail.com>

* Allow URLs without `user` part

Refer to #1877

* Update docs

* Allow Redis DSN with schema only

Refer to https://github.com/samuelcolvin/pydantic/pull/1911#issuecomment-722335692
Refer to https://www.iana.org/assignments/uri-schemes/prov/redis

* Fix lint error

* Fix lint error

* Set `parts: Dict[str, Optional[str]]` instead of `Dict[str, str]`

* Fix linting

* More verbose default values set in `RedisDsn.validate_parts()`

* Fix linting 2

* Fix typo in docs

* Add a note in the changelog

* Add test case for URL without `user` part

* change port in test

Co-authored-by: PrettyWood <em.jolibois@gmail.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Samuel Colvin <s@muelcolvin.com>
2020-12-30 18:20:51 +00:00
Rick Izzo 465f267c7d Added StrictBytes type (#2136)
* 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>
2020-12-01 01:18:35 +01:00