Commit Graph

431 Commits

Author SHA1 Message Date
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
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
Eric Jolibois 0ebea889f6 build(deps): bump requirements (#3495)
* chore(deps): bump requirements

* style: format after black bump
2021-12-07 10:36:41 +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
Eric Jolibois a35cde90af feat(schema): set minItems and maxItems in JSON schema for tuples (#2497)
* feat(schema): enforce length in generated JSON schema for tuple type

* docs: add change file

* docs: update documentation

* simplify a bit

* always set array
2021-12-05 13:20:07 +00:00
Colin Watson cc1cb4826c Fix "dataclasess" typos (#3411) 2021-11-18 23:41:56 +01: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
Dylan Leroux 36140bb177 typo (#3242) 2021-10-27 01:26:04 +02:00
Eric Jolibois 28f7b1ba58 build(deps): bump requirements (#3363) 2021-10-27 01:12:20 +02:00
Greg Wilson d2625d6052 docs: small change to wording in note (#3347) 2021-10-27 00:55:04 +02:00
dependabot[bot] eac8a457d1 build(deps): bump hypothesis from 6.18.0 to 6.24.0 (#3353)
Bumps [hypothesis](https://github.com/HypothesisWorks/hypothesis) from 6.18.0 to 6.24.0.
- [Release notes](https://github.com/HypothesisWorks/hypothesis/releases)
- [Commits](https://github.com/HypothesisWorks/hypothesis/compare/hypothesis-python-6.18.0...hypothesis-python-6.24.0)

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

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

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-10-27 00:41:04 +02:00
Eric Jolibois 4be3f45e20 chore(deps): bump mkdocs (#3168)
* chore(deps-dev): bump mkdocs requirements

* fix: google analytics

`google_analytics` is deprecated and mkdocs raises an error in strict mode
Switched to new syntax
https://github.com/squidfunk/mkdocs-material/issues/2055
https://squidfunk.github.io/mkdocs-material/setup/setting-up-site-analytics/#google-analytics
2021-10-12 22:46:47 +01:00
dependabot[bot] c256dccbb3 build(deps): bump hypothesis from 6.17.4 to 6.18.0 (#3183)
Bumps [hypothesis](https://github.com/HypothesisWorks/hypothesis) from 6.17.4 to 6.18.0.
- [Release notes](https://github.com/HypothesisWorks/hypothesis/releases)
- [Commits](https://github.com/HypothesisWorks/hypothesis/compare/hypothesis-python-6.17.4...hypothesis-python-6.18.0)

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

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

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-09-11 10:49:52 +02:00
Sebastián Ramírez 45db4ad3aa Add autocomplete support for VS Code, via dataclass_transform (#2721)
*  Add autocomplete support for VS Code, via dataclass_transform

* 📝 Update changes

* 📝 Add docs for VS Code

* 📝 Clarify strict type error checks alternatives, include example with cast()

* ♻️ Update BaseSettings annotation to improve editor support

keeping editor support for BaseSetting's custom Config, but preventing __config__ from showing in constructor on editors supporting dataclass_transform

* 🎨 Remove unused type: ignore comment

* 🎨 Update type annotations for BaseSettings and BaseModel to use ClassVar where suitable

to improve editor support with type annotations and dataclass_transform

* 🎨 Apply ClassVars again

* 📝 Simplify VS Code docs terms

refer mainly to Pylance and clarify the relationship with Pyright

* 📝 Add link to Pylance FAQ

Co-authored-by: PrettyWood <em.jolibois@gmail.com>
2021-09-06 12:13:02 +02:00
John Walk 0c2f69c500 Toml support for pydantic-mypy plugin config (#2908)
* add toml reader

* fix path

* skip configparser step

* fix quotes

* full pyproject.toml check

* add doc note

* cleaner formatting, raise ValueError for non-bool

* fix tests

* add bad config test case

* add changelog file.

* bump mypy to 0.902

* tweak change MD, fix formatting in requirements

* import check around toml

* switch to tomli for parsing to match mypy dependency

* import check around toml/tomli

* add note on tomli usage

* more succinct changelog entry

* fix quotes in changelog

* linting fixes, remove unnecessary stub install

* mypy checks on mypy plugin file

* wrongly placed pragma no cover

Co-authored-by: PrettyWood <em.jolibois@gmail.com>
2021-09-05 11:25:47 +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
Pax 4ac2501477 mention 3.8 requirement in contrib docs (#2856)
* mention 3.8 requirement in contrib docs

* add change.md for PR#2856

* docs: fix grammar and wording
2021-09-04 19:55:40 +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
Eric Jolibois 796a7531cd chore(deps): bump requirements (#3166)
* chore(deps): bump requirements

* chore(deps-dev): bump lint requirements

* chore(deps-dev): add test requirements

* chore(deps-dev): last bumps

* fix: mypy update

* chore: docs bumps
2021-09-03 23:47:51 +02:00
Eric Jolibois 4a54f393ad Add python 3.10 support (#2885)
* refactor: extra `BaseConfig` and `Extra` in dedicated `config` module

* refactor: clean useless `#noqa: F401`

* refactor: clean useless `#noqa: F811`

* refactor: replace enum check

Error with 3.10
> DeprecationWarning: accessing one member from another is not supported

* refactor: avoid using `distutils` directly

error with python 3.10
> DeprecationWarning: The distutils package is deprecated and slated
> for removal in Python 3.12.
> Use setuptools or check PEP 632 for potential alternatives

* fix: `__annotations__` always exists

* fix: origin of `typing.Hashable` is not `None`

* ci: add run with 3.10.0b2

* docs: add 3.10

* feat: support `|` union operator properly

`|` operator has origin `types.Union` (and not `typing.Union`)

* fix: enum repr is different with 3.10+

* fix: error message changed a bit

change from basic `__init__` to `test_hashable_required.<locals>.MyDataclass.__init__()` (with `__qualname__`)

* fix:  always exists and is not inherited anymore

* fix: avoid calling `asyncio.get_event_loop` directly

With python 3.10, calling it results in
> DeprecationWarning: There is no current event loop

* fix(ci): do not run 3.10 on linux for now

For now it can not be compiled.
Let's just skip the check on linux for now instead of tuning the CI pipeline

* fix(ci): ignore DeprecationWarning raised by `mypy` on windows

* docs: add change file
2021-07-19 14:23:07 +01: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
Peter Roelants 2e2edf4f11 Allow custom CFLAGS and update documentation on reducing size. (#2517)
Squashed commit Co-authored-by: Eric Jolibois <em.jolibois@gmail.com>
2021-06-04 21:42:49 +02:00
Ratul Maharaj aca18a9863 Added Talk Python Episode 313 to docs (#2712)
* Added Talk Python Episode 313

* Added changes file

* Update docs/index.md

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

* Fixed typo in Michael's name

Co-authored-by: Eric Jolibois <em.jolibois@gmail.com>
2021-06-04 19:41:01 +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
Eric Jolibois 2549c3012d build(deps-dev): bump dependencies (#2867)
black:              21.4b0 ->  21.5b2
flake8:              3.9.1 ->   3.9.2
hypothesis:         6.10.1 -> 6.13.10
mkdocs-material:     7.1.4 ->   7.1.6
pytest:              6.2.3 ->   6.2.4
pytest-cov:         2.11.1 ->  2.12.0
typing-extensions: 3.7.4.3 ->  3.10.0.0
2021-06-01 18:46:05 +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
dependabot[bot] 6df783e9b4 build(deps): bump mkdocs-material from 7.1.3 to 7.1.4 (#2773)
Bumps [mkdocs-material](https://github.com/squidfunk/mkdocs-material) from 7.1.3 to 7.1.4.
- [Release notes](https://github.com/squidfunk/mkdocs-material/releases)
- [Changelog](https://github.com/squidfunk/mkdocs-material/blob/master/docs/changelog.md)
- [Commits](https://github.com/squidfunk/mkdocs-material/compare/7.1.3...7.1.4)

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

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-05-11 21:40:27 +01:00
Samuel Colvin 7a2bcd2f6a switch downloads badge to pepy.tech 2021-05-11 15:13:29 +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
krisaoe 42395056e1 Fix(docs): remove colon to separate unrelated clauses (#2733)
* Fix(docs): remove colon to separate unrelated clauses 

The colon at the end of the line "The fields which were supplied when user was initialised:" suggests that the code following it is related.
Changed it to a period.

* Include change summary readme.
2021-05-03 17:46:37 +01:00
dependabot[bot] 157e115500 build(deps): bump hypothesis from 6.8.5 to 6.10.1 (#2728)
Bumps [hypothesis](https://github.com/HypothesisWorks/hypothesis) from 6.8.5 to 6.10.1.
- [Release notes](https://github.com/HypothesisWorks/hypothesis/releases)
- [Commits](https://github.com/HypothesisWorks/hypothesis/compare/hypothesis-python-6.8.5...hypothesis-python-6.10.1)

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

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-05-01 17:22:18 +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
dependabot[bot] a7fe5ea201 build(deps): bump mkdocs-material from 7.1.0 to 7.1.3 (#2699)
Bumps [mkdocs-material](https://github.com/squidfunk/mkdocs-material) from 7.1.0 to 7.1.3.
- [Release notes](https://github.com/squidfunk/mkdocs-material/releases)
- [Changelog](https://github.com/squidfunk/mkdocs-material/blob/master/docs/changelog.md)
- [Commits](https://github.com/squidfunk/mkdocs-material/compare/7.1.0...7.1.3)

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

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-05-01 16:08:19 +01:00
dependabot[bot] d34ea05f60 build(deps): bump flake8 from 3.9.0 to 3.9.1 (#2682)
Bumps [flake8](https://gitlab.com/pycqa/flake8) from 3.9.0 to 3.9.1.
- [Release notes](https://gitlab.com/pycqa/flake8/tags)
- [Commits](https://gitlab.com/pycqa/flake8/compare/3.9.0...3.9.1)

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

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-05-01 16:06:54 +01:00
Edd Salkield ae13be5b8c docs: minor typo correction (#2649) 2021-04-10 11:21:51 +02:00
Eric Jolibois 14f055e743 fix(docs): url schema -> scheme (#2634) 2021-04-05 15:36:21 +02:00
wackazong 7fb77a779a Documentation: Put examples for config to the start of the section (#2615)
* Put examples to the start of the section

I think this is where they belong, they were in the middle of the list of config options somewhere near the end.

* Add "options" in table of contents

* tweak

Co-authored-by: Eric Jolibois <em.jolibois@gmail.com>
2021-04-05 12:40:13 +02:00
dependabot[bot] 22ba2ca21a build(deps): bump hypothesis from 6.3.4 to 6.8.5 (#2624)
* build(deps): bump hypothesis from 6.3.4 to 6.8.4

Bumps [hypothesis](https://github.com/HypothesisWorks/hypothesis) from 6.3.4 to 6.8.4.
- [Release notes](https://github.com/HypothesisWorks/hypothesis/releases)
- [Commits](https://github.com/HypothesisWorks/hypothesis/compare/hypothesis-python-6.3.4...hypothesis-python-6.8.4)

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

* fix mypy issues

* build(deps): bump hypothesis from 6.8.4 to 6.8.5

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: PrettyWood <em.jolibois@gmail.com>
2021-04-05 12:19:17 +02:00
dependabot[bot] 39fd02e065 build(deps): bump mkdocs-material from 7.0.6 to 7.1.0 (#2632)
Bumps [mkdocs-material](https://github.com/squidfunk/mkdocs-material) from 7.0.6 to 7.1.0.
- [Release notes](https://github.com/squidfunk/mkdocs-material/releases)
- [Changelog](https://github.com/squidfunk/mkdocs-material/blob/master/docs/changelog.md)
- [Commits](https://github.com/squidfunk/mkdocs-material/compare/7.0.6...7.1.0)

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

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-04-05 12:14:07 +02:00
Joe 282d5b847d Fix indent level of "Validating the first value" (#2577) 2021-04-05 11:30:30 +02:00
William Woodruff ec1bf696e9 doc(schema): fix a callout (#2620)
* doc(schema): use boldface to highlight a note

* doc(schema): fix small formatting typo

* doc(schema): attempt to fix the callout

* docs(schema): indent the callout
2021-04-05 11:25:32 +02:00