198 Commits

Author SHA1 Message Date
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
gr8jam 7c6e7e3bac Fixed datetime format specifier in docs (#4876) 2022-12-27 09:17:16 +01:00
Muhammad Abdur Rakib f2b129a8bc fixed documentation typo (#4855) 2022-12-20 13:53:01 +01:00
Hasan Ramezani 9588c9e22d Fix typo in types usage documentation. (#4825) 2022-12-15 11:58:24 +00:00
Marcelo Trylesinski caa318c908 Remove trailing "```" (#4799) 2022-11-29 15:43:30 +01:00
Irfanuddin Shafi Ahmed 9949786caf fix typo in docs (#4764) 2022-11-17 10:01:00 +00:00
Volker Hilsenstein 2f090a5cca Fix broken cross-references (#4743)
Co-authored-by: Volker Hilsenstein <volker.hilsenstein@embl.de>
2022-11-10 16:32:49 +00:00
Evorage 5cbfcba510 Trivial Markdown Fix (#4711) 2022-11-03 11:42:13 +00:00
Mòrian 5dd9b4f5ca Add postgresql+psycopg as allowed scheme for PostgreDsn (#4689) (#4690) 2022-10-31 10:37:57 +00:00
Zach Kirsch a44d373f1f Fix "trough" typo in Model Config docs (#4593) 2022-10-07 09:15:47 +02:00
Dmitry Lavrentev 996101b8ba fix: missing file extension in model_config.md link (#4512) 2022-09-13 09:39:31 +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 f341049b9e Remove Cython & Move to pyproject.toml (#4473)
* 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
2022-09-06 17:15: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
Samuel Colvin dd5f2a55aa fix links 2022-08-22 22:32:56 +01:00
Samuel Colvin 5b2bcfd73c correct copy_on_model_validation docs (#4420)
* correct "copy_on_model_validation" docs, fix #4369

* Update docs/usage/model_config.md

* correct docs
2022-08-22 22:00:18 +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
Sebastián Ramírez 8dade7e9ac Add JSON-compatible float constraints for NaN and Inf (#3994)
*  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>
2022-08-22 15:21:56 +01:00
Hasan Ramezani abcf81ec10 Rename master to main (#4405) 2022-08-19 18:49:13 +01: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
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
Hasan Ramezani c5d57b7cf5 Fix the behavior change in .json() documentation (#4371)
* Fix the behavior change in `.json()` documentation

* Add breaking change to original change in HISTORY.md
2022-08-14 17:46:24 +00: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
hottwaj cdd091c8ac Initial implementation of ConstrainedDate, condate (#3740)
* 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>
2022-08-12 14:37:41 +00:00
Kyungmin Lee 0320a99361 feat: add support multiple dotenv files (#1497) (#3222)
* feat: support multiple dotenv files

Allow BaseSettings to accept multiple dotenv files in Config as a list
or tuple.

* docs: add multiple dotenv support

* docs: add a change summary

* test: add missing tests

* fix: test coverage

* refactor: raise a TypeError when an object of an invalid type is passed

* fix: a lint error

* refactor: remove `_read_process_env_vars` method

* docs: update priority

* refactor: apply a review

* test: simplify testing

* refactor: apply reviews

* reverse piority order, reduce diff size

* fix change file grammar

* correct docs, avoid unnecessary copy of os.environ

* correct wording in docs

Co-authored-by: Samuel Colvin <s@muelcolvin.com>
2022-08-12 12:17:01 +00: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 a9c273235f Fix sub-model link in usage/models docs (#4234) 2022-08-09 10:51:52 +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
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