Commit Graph

885 Commits

Author SHA1 Message Date
Samuel Colvin a7656fcd09 Support extracting attributes from the parent namespace (#4663)
* support extracting attributes from the parent namespace

* fix more tested test

* move parent_frame_namespace
2022-11-08 10:26:24 +00:00
Samuel Colvin 8d98c499df url parsing in pydantic-core (#4732)
* url parsing in pydantic-core

* fix tests

* fix mypy tests
2022-11-08 09:42:38 +00:00
Adrian Garcia Badaracco 9e1f2a6f7c feat: add strict to Field (#4713)
* feat: add strict to Field

* skip if not set

* Update pydantic/fields.py

* Move model into fixture
2022-11-07 16:40:19 +00:00
Samuel Colvin a57346ac49 Move to ruff for linting (#4709)
* WIP to move to ruff for linting

* add extend-select, fix string
2022-11-03 13:45:34 +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
Mòrian 5dd9b4f5ca Add postgresql+psycopg as allowed scheme for PostgreDsn (#4689) (#4690) 2022-10-31 10:37:57 +00:00
Samuel Colvin ee52496101 Email tweaks (#988)
* small tweaks to email validation

* more test examples

* change and better error messages

* remove duplicate tests

* linting

* tweak from @hramezani
2022-09-08 15:46:58 +00: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
Eric Jolibois f1e9883157 fix: dataclass wrapper was not always called (#4484) 2022-09-05 17:32:29 +01:00
Sveinung Gundersen 91bb8d4482 Basic fix of GenericModel cache to detect order of args in Union models [#4474] (#4482) 2022-09-05 15:51:20 +01:00
Samuel Colvin eccd85e4d0 prevent long strings as int inputs (#4480)
* prevent long strings as int inputs, fix #1477

* fix tests 🤦

* fix length in change file
2022-09-05 12:35:08 +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 02cf7f5d7b fix mypy with default_factory=list etc. (#4471)
* fix mypy with default_factory=list etc.

* fix tests

* add error case
2022-09-05 11:01:43 +01:00
dependabot[bot] 317bef33b0 build(deps): bump black from 22.6.0 to 22.8.0 (#4465)
Bumps [black](https://github.com/psf/black) from 22.6.0 to 22.8.0.
- [Release notes](https://github.com/psf/black/releases)
- [Changelog](https://github.com/psf/black/blob/main/CHANGES.md)
- [Commits](https://github.com/psf/black/compare/22.6.0...22.8.0)

---
updated-dependencies:
- dependency-name: black
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

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

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-09-01 23:49:25 +02:00
dependabot[bot] 2add8a9482 build(deps): bump hypothesis from 6.54.3 to 6.54.4 (#4464)
Bumps [hypothesis](https://github.com/HypothesisWorks/hypothesis) from 6.54.3 to 6.54.4.
- [Release notes](https://github.com/HypothesisWorks/hypothesis/releases)
- [Commits](https://github.com/HypothesisWorks/hypothesis/compare/hypothesis-python-6.54.3...hypothesis-python-6.54.4)

---
updated-dependencies:
- dependency-name: hypothesis
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

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

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-09-01 23:49:06 +02:00
Grzegorz Bokota 3a2e83ce64 Add __hash__ operator to Color class (#4455)
* add __hash__ operator to Color

* add changes file

* fix code style

* add type annotation

* Update changes/4455-czaki.md

Co-authored-by: Hasan Ramezani <hasan.r67@gmail.com>

Co-authored-by: Hasan Ramezani <hasan.r67@gmail.com>
2022-08-31 10:53:59 +01:00
Samuel Colvin b065908490 fix type hints in BaseSettings.Config (#4450)
* fix type hints in BaseSettings.Config

* add tests and change notice
2022-08-30 13:08:23 +01:00
Samuel Colvin 0244b06be5 Warn and ignore __slots__ argument to create_model (#4432)
* add test for create_model with slots

* add test for create_model with slots

* add warning and change description

* fix flakey none tests on 3.8.10

* avoid flakey coverage changes
2022-08-24 20:13:07 +01:00
Samuel Colvin f708c32f89 avoid docs update on pre-release (#4429) 2022-08-24 12:27:50 +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
Talley Lambert beb3e4c8f1 Fix duplicate calls to __set_name__ for non-private attributes in BaseModel.__new__ (#4410)
* fix: double call for public attrs, extend test

* add changes

* remove change file, update 4407 file
2022-08-22 11:16:53 +00:00
Talley Lambert d501c39f2b Fix PEP487 __set_name__ protocol in BaseModel (#4407)
* fix: fix __set_name__ protocol in BaseModel

* undo changes

* add comment

* fix lint

* fix lint

* add change file

* remove mock, move imports
2022-08-21 13:53:26 +00:00
Hasan Ramezani abcf81ec10 Rename master to main (#4405) 2022-08-19 18:49:13 +01:00
DetachHead 9585ef3475 fix dataclass containing Any (#4356)
Co-authored-by: detachhead <detachhead@users.noreply.github.com>
2022-08-19 11:46:09 +01:00
dependabot[bot] 4c37e662e3 build(deps): bump hypothesis from 6.54.1 to 6.54.3 (#4403)
Bumps [hypothesis](https://github.com/HypothesisWorks/hypothesis) from 6.54.1 to 6.54.3.
- [Release notes](https://github.com/HypothesisWorks/hypothesis/releases)
- [Commits](https://github.com/HypothesisWorks/hypothesis/compare/hypothesis-python-6.54.1...hypothesis-python-6.54.3)

---
updated-dependencies:
- dependency-name: hypothesis
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

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

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-08-19 10:27:30 +00:00
dependabot[bot] a8c6af0e7f build(deps): bump coverage from 6.4.3 to 6.4.4 (#4402)
Bumps [coverage](https://github.com/nedbat/coveragepy) from 6.4.3 to 6.4.4.
- [Release notes](https://github.com/nedbat/coveragepy/releases)
- [Changelog](https://github.com/nedbat/coveragepy/blob/master/CHANGES.rst)
- [Commits](https://github.com/nedbat/coveragepy/compare/6.4.3...6.4.4)

---
updated-dependencies:
- dependency-name: coverage
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

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

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-08-19 10:03:24 +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
chbndrhnns ba58f94150 feat: Make SecretStr hashable (#4399)
* 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>
2022-08-19 09:13:30 +00:00
Hasan Ramezani 899b5f0661 Fix StrictStr does not raise ValidationError when max_length is present in Field (#4388) 2022-08-19 09:51:59 +01:00
Jean 67b653f19a fix: strictbytes-max-length (#4383)
* fix: strictbytes-max-length

* fix: apply feedbacks

* Update changes/4380-JeanArhancet.md

Co-authored-by: Hasan Ramezani <hasan.r67@gmail.com>

Co-authored-by: Hasan Ramezani <hasan.r67@gmail.com>
2022-08-16 23:41:17 +02: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 dab478aa81 Add support for bare type (#4375) 2022-08-14 21:52:34 +01:00
Samuel Colvin 11903e3f41 fix tests when mypy is not installed 2022-08-12 15:51:52 +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
KotlinIsland 03606916e4 Fix mypy version check (#3783)
* fix mypy version check

* fix mypy version check

* implement parse_mypy_version and test

* add change file

Co-authored-by: KotlinIsland <kotlinisland@users.noreply.github.com>
Co-authored-by: Samuel Colvin <s@muelcolvin.com>
2022-08-12 15:07:43 +01: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
Hasan Ramezani 104748c793 Add support for re.Pattern (#4366) 2022-08-12 12:36:15 +01:00
Samuel Colvin 47362e33b6 Pick 1.9 (#4350)
* 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>
2022-08-12 11:09:49 +01:00
Samuel Colvin 5c8942bdd4 Revert "Add nested json encoding (#3941)" (#4367)
This reverts commit b42fae081c.
2022-08-12 11:08:33 +01:00
Matt Coneybeare b8a695788e Catch Exceptions in smart_deepcopy (#4187)
* Catch Exceptions in smart_deepcopy

* address feedback
2022-08-12 07:56:47 +00:00
Amin Alaee fa6b9788a1 Allow BaseModel schema to have fields of type Type (#4154)
* 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>
2022-08-11 11:47:30 +00:00
Amin Alaee 1f83221323 Fix imports indirectly from pydantic typing (#4358)
* Fix imports indirectly from pydantic typing

* fix pipeline

* Add MappingIntStrAny to __all__

* fix ForwardRef

* Fix Callable

* remove from ForwardRef imports

* Add changes
2022-08-11 12:35:56 +01:00
DetachHead 1e821b6df4 fix "extra fields not permitted" error when dataclass with Extra.forbid is validated multiple times (#4354)
Co-authored-by: detachhead <detachhead@users.noreply.github.com>
2022-08-11 11:23:57 +00:00
Kyle Amos a587ecee88 Fix #4192 bug with BaseModel.construct and aliased Fields (#4191)
* 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>
2022-08-11 11:49:07 +01:00
Max McLennan 4cb58cf9df Discriminated union schemas use oneOf instead of anyOf (#4335) 2022-08-11 11:42:28 +01:00
Hasan Ramezani 149c05bc2e Fix __post_init_post_parse__ is incorrectly passed keyword arguments when no __post_init__ is defined (#4361) 2022-08-11 12:40:50 +02:00
arsenron 6650edfe8f Fix #3807: matching characters in nested env delimeter and env prefix (#3975)
* fix nested env delimeter with matching prefix

* Update env_settings and add change readme

* fix change and add comment

Co-authored-by: Samuel Colvin <s@muelcolvin.com>
2022-08-11 11:35:03 +01:00
chenyijian 02a2a8b5c0 create_model support generics model (#3946)
* create_model support generics model

* fix change.

Co-authored-by: chenyijian <chenyijian@mycapital.net>
Co-authored-by: Samuel Colvin <samcolvin@gmail.com>
2022-08-11 10:34:24 +00:00