Commit Graph

170 Commits

Author SHA1 Message Date
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
Tiemo cf16f7c388 Add CockroachDsn type (#3830)
* 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>
2022-08-08 15:14:35 +00:00
gieddy660 9599a3d256 updates to description of the fields option. (#3822)
* 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>
2022-08-08 14:53:43 +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
Yasser Tahiri e07d73b373 Update URLs after migrating to organization (#4348)
* update URLs

* add a change file
2022-08-08 12:27:35 +00:00
PattyC d0e5f98be4 new to_lower_camel() function (#3473)
* 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>
2022-08-05 14:18:19 +00:00
Piotr Rogulski 5885e6ce12 fix(PostgresDsn): Add support for multiple hosts in PostgresDsn #3337 (#3349)
* 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>
2022-08-05 13:57:16 +00:00
Salar Nosrati-Ershad d53259aa58 Add MongoDB network data source name (DSN) schema (#3230)
* 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
2022-08-04 16:10:42 +01:00
Will McGugan e58dad6dec Added support for Rich Repr protocol (#3099)
* 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>
2022-08-04 13:47:42 +00: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
Hasan Ramezani 6cc38feeb1 Add ISO 8601 wikipedia link to docs (#4263) 2022-08-03 16:19:15 +01:00
Dror Atariah a21f0763ee Improved example ind models doc (#4231)
Co-authored-by: Hasan Ramezani <hasan.r67@gmail.com>
2022-07-18 09:06:31 +02:00
Amin Alaee 228e46de35 Update docs for dotenv env_file not checking parent directories (#4150) 2022-07-14 18:39:28 +02:00
Amin Alaee 962ea8bf21 Add docs for defining upper-case variables on nested setting models (#4153) 2022-07-05 20:04:46 +02:00
Jochen Kupperschmidt 058d4a52ee Tweak documentation (#4143) 2022-07-04 22:53:11 +02:00
Ben Nuttall 33ae990c76 Fix model_config documentation (#4179) 2022-07-03 13:15:54 +02:00
Tetsuo Kiso d7593368c7 Fix typo in models.md (#4145) 2022-07-03 13:11:56 +02:00
Samuel Colvin 8997cc5961 Remove benchmarks completely (#3973)
* removing benchmarks completely

* [no ci] add change
2022-04-04 13:29:17 +01:00
Gary Donovan 7f90b2f342 Remove incorrect comment about lazy evaluation of setting sources (#3806)
* Remove incorrect comment about lazy evaluation of setting sources

It looks like the current implementation always evaluates every source (https://github.com/samuelcolvin/pydantic/blob/9d631a3429a66f30742c1a52c94ac18ec6ba848d/pydantic/env_settings.py#L73) before coalescing them into a single dictionary to pass to `BaseModel`. So the comment about lazy evaluation is incorrect and should be removed.

* Add changelog
2022-04-02 15:25:43 +01:00
Tom Milligan 02eb182db0 fix: clarify that discriminated unions do not support singletons (#3639) 2022-04-02 14:06:11 +01:00
Guilhem C 90628e1c2b docs: fix typo in settings management page (#3781) 2022-04-01 19:47:05 +01:00
Samuel Colvin 6f46a5a146 drop python3.6 support (#3605)
* drop python3.6 support

* revert small change

* fix 3.7 failures

* more cases and cleanup

* add change description
2022-01-02 13:53:45 +00: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
Sebastián Ramírez 61d30aed7a Add support for decimal-specific configs in Field() (#3507)
*  Add support for Decimal-specific configs in Field()

*  Add/update tests for condecimal and variant with Field()

* 📝 Update schema - Field() docs including Decimal-specific configs

* 📝 Add PR changes file
2021-12-11 11:21:06 +00:00
Nuno André 91ecfd651e feat: Add unique items validation to constrained lists (#2618)
* 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>
2021-12-10 10:04:06 +00:00
Eric Jolibois 8c2c602c1b feat: add confrozenset() (#2672)
* feat: add `confrozenset()`

* fix: add tests for allowed_schemas
2021-12-07 22:11:42 +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
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
Tom Hacohen 8afdaab4ac Schema.md: use consistent (American) spelling (#3207)
Customisation is the British spelling. Below (and elsewhere) the American
spelling (customization) is used.
2021-10-27 01:28:27 +02:00
Josh Smith 7acac76f3c fix minor typo (#3240) 2021-10-27 01:26:52 +02:00
Greg Wilson d2625d6052 docs: small change to wording in note (#3347) 2021-10-27 00:55:04 +02:00
Pax e431604654 clarify docs on validation and strict type checking (#2855)
* clarify docs on validation and strict type checking

Related: Issue#578

Co-authored-by: cknoll <unknown@exampleemail.com>
Co-authored-by: PyAntony <unknown@exampleemail.com>

* add change.md for PR#2855

* docs: explicitly specify _partial_ support

* chore: update formatting of change description

Co-authored-by: cknoll <unknown@exampleemail.com>
2021-09-04 19:58:47 +02:00
Eric Jolibois f9c65c5b88 fix: add/fix BaseConfig type annotations (#2720) 2021-09-04 04:13:20 +02:00
Vasilis Gerakaris 8417b3bb5c add FileUrl type for file:// schemes, add host_required parameter (#2434)
* 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>
2021-09-04 02:10:25 +02:00
Fernando ike 1a9f59dc1e Support postgresql+asyncpg schema for PostgresDsn (#2567)
* 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>
2021-09-04 01:19:54 +02:00
Christian Clauss 90080ba0de Fix typos discovered by codespell (#3096) 2021-09-04 00:05:36 +02:00
Marcelo Trylesinski a4cb4ee3bc feat: add PastDate and FutureDate types (#2425)
* feat: add PastDate and FutureDate types

* add changes file

* add tests

* fix: json schema

* fix: black format

* less code duplicated

* add dates on success.py

* fix past and future dates

* ♻️ Apply Samuel's comments

* 🚨 Satisfy flake8

* 🔥 Remove _DateValueError

* test: add last explicit case

Co-authored-by: PrettyWood <em.jolibois@gmail.com>
2021-06-04 23:30:25 +02:00
Eric Jolibois c489445cea fix: mypy plugin link in docs (#2869) 2021-06-01 23:01:39 +02:00
Rémi Benoit 920d71b708 Fix mypy plugin link in doc (#2747) 2021-06-01 22:35:10 +02: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
Frank Epperlein 362f4a5163 add repr parameter to hide a field from repr() (#2593)
* add repr parameter to hide a field from repr()

* fix styling issues

… found by flake8.

* fix type annotation issues

* correctly name changes file

* test hiding default values from repr() of a Field

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

Co-authored-by: Eric Jolibois <em.jolibois@gmail.com>
2021-05-09 14:16:52 +01:00
Eric Jolibois 31c4efb7f0 fix: remove side effect of default_factory to always run it only once (#2566) 2021-05-09 13:35:15 +01:00
Koudai Aono 07908b3846 Add "strict" argument to "conbytes" (#2490)
* Add "strict" argument to "conbytes"

* Add unittest

* Update changes/2489-koxudaxi.md

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

Co-authored-by: Eric Jolibois <em.jolibois@gmail.com>
2021-05-09 10:27:29 +01:00