Commit Graph

51 Commits

Author SHA1 Message Date
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
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 dd5f2a55aa fix links 2022-08-22 22:32:56 +01:00
Hasan Ramezani abcf81ec10 Rename master to main (#4405) 2022-08-19 18:49:13 +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
Hasan Ramezani a9c273235f Fix sub-model link in usage/models docs (#4234) 2022-08-09 10:51:52 +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
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
Jochen Kupperschmidt 058d4a52ee Tweak documentation (#4143) 2022-07-04 22:53:11 +02:00
Tetsuo Kiso d7593368c7 Fix typo in models.md (#4145) 2022-07-03 13:11:56 +02: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
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
Christian Clauss 90080ba0de Fix typos discovered by codespell (#3096) 2021-09-04 00:05:36 +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
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
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
Edd Salkield ae13be5b8c docs: minor typo correction (#2649) 2021-04-10 11:21:51 +02:00
Samuel Colvin aff4a41f9d preparing for v1.8 (#2414)
* preparing for v1.8 🎉 🚀

* change description for #2415

* tweak change descriptions

* fix nested lists in docs

* remove items in 1.7.3 from 1.8
2021-02-26 16:30:08 +00:00
layday 78934db631 PropagateClassVars to sub-models (#2179)
* Propagate`ClassVar`s to sub-models

Currently, if a `ClassVar` is defined on a model and re-defined
on a sub-model omitting the `ClassVar` annotation, Pydantic produces an
unrelated error:

    NameError: Field name "..." shadows a BaseModel attribute ...

This check was introduced to prevent shadowing Pydantic's own methods
and attributes defined on the `BaseModel` class.  Following this change,
class variables (that is, variables annotated with `ClassVar`)
defined on parent models will be inherited by sub-models and
will be overwritable without having to reapply the annotation.

Closes #2061.

* docs: explain how attributes are excluded and when to use `PrivateAttr`
2021-02-13 14:52:39 +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
Arseny Boykov 664cbcfc01 Add private attributes support (#1679)
* Add private attributes support

* Add more blank lines in example

* Add changes file

* Update docs/usage/models.md

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

* fix after bad merge

* Add PrivateAttr, Config.underscore_attrs_are_private

* remove unrelated change in utils.py

* add   # noqa: C901 (ignore complexity) to __setattr__
(see comment in PR)

* add annotation to Config.underscore_attrs_are_private

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

* use sunder names

* mention underscore_attrs_are_private in model_config.md

* add comment about default factory

* fix comment

* fix comment

* clarify that both dunder and sunder names might be used

* tweak docs and name

* _set_default_private_attributes -> _init_private_attributes

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

* use new name _init_private_attributes

* move tests

* copy private attributes in BaseModel.copy()

* add test for default and default_factory used together

* fix linting

* more tests, default_factory kw only

Co-authored-by: Samuel Colvin <samcolvin@gmail.com>
Co-authored-by: Samuel Colvin <s@muelcolvin.com>
2020-10-26 09:47:40 +00:00
Chris Hoogeboom 0af5e5f559 Allow generics to extend concrete classes. fixes #2005 (#2006)
* Allow generics to extend concrete classes. fixes #2005

* Update the docs

* Updote the changes

* Convert double quotes to single quotes

* Fix formatting

* Add a check for data

* Update example

* Add a skip_36 decorator that got accidentally deleted when resolving conflicts.
2020-10-25 19:22:25 +00:00
Benjamin Sitruk e00dba322b Docs: Add validators to dynamic model (#1963)
* Add dynamic validators to doc

* Update models_dynamic_validators.py

* Update models_dynamic_validators.py

* Adding example (success and error)

* Update models_dynamic_validators.py
2020-10-25 17:57:08 +00:00
Geon Kim - KimMachineGun be8ef63a33 docs: Fix incorrect description of copy method (#1821)
* docs: Fix typo

* docs: Fix incorrect description of copy method

* changes: Add changes description file

* docs: Add space before parentheses

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

Co-authored-by: PrettyWood <em.jolibois@gmail.com>
2020-10-09 11:28:04 +01:00
PrettyWood 75859a9d58 feat(tools): add parse_raw_as util (#1813)
closes #1812
2020-10-09 10:35:07 +01:00
Matthew Davis 094da94da9 clarify argument type to parse_file (#1795)
Co-authored-by: Matthew Davis <Matthew.Davis.2@team.telstra.com>
2020-10-08 21:10:09 +01:00
PrettyWood c59db275dc fix(field): remove some side effects of default_factory (#1504)
* Avoid some side effects of default factory

- by calling it only once if possible (fix #1491)
- by not setting the default value in the schema (fix #1520)

* refactor: ensure type is set when using default_factory
2020-06-27 14:02:29 +01:00
Fredrik Jonsén 97b6b46268 docs: add missing period and capitalize where appropriate (#1653) 2020-06-23 18:47:39 +01:00
Samuel Colvin 63ec6fffe3 update docs on generics, fix #1547 (#1584) 2020-05-31 15:08:57 +01:00
Luka Peschke 1bff80459d Add an example to documentation for reserved ORM field names (#1474)
Signed-off-by: Luka Peschke <mail@lukapeschke.com>
2020-05-31 14:44:23 +01:00
Samuel Colvin 67acb659c2 prepare v1.5 release 2020-04-18 17:32:16 +01:00
mikuhn 91c626eee0 docs: add hint for custom root types (#1373)
fix #1372

Co-authored-by: Michael Kuhn <michael.kuhn@uni-tuebingen.de>
2020-04-15 22:53:19 +01:00
PrettyWood 78a3f42b0a Dynamic default value (#1210)
* Simplify dynamic default values

closes #866

* Add documentation and change

* Add `ModelField.get_default` method

* Fix default value in `infer`

Co-Authored-By: Samuel Colvin <samcolvin@gmail.com>

Co-authored-by: Samuel Colvin <samcolvin@gmail.com>
2020-03-04 16:37:23 +00:00
Thaïs de Boisfossé 679e5d149e Generics inherit doc (#1249)
* doc: add an example of inheritance with Generics

* Update the changes directory with the doc changes.
2020-03-04 15:40:04 +00:00
Arseny Boykov 0f948618ba Add model signature generation (#1034)
* Add right __init__ signature generation

* Add params overlay support for custom __init__, enhance tests

* Change fake_ini creation to solve AttributeError in cython
AttributeError: attribute '__code__' of 'cython_function_or_method' objects is not writable
Possible there's other attrs that cannot be set in cython, but can't check myself yet

* Cython compatibility, add __signature__, ignore non-identifiers fields
Moved tests to separate file
Moved __init__ creation to utils

* Remove # pragma: no cover

Co-Authored-By: Samuel Colvin <samcolvin@gmail.com>

* Fixed adding signature to doc, some compatibility fixes

* Changed None to tuple() for py3.8 compatibility

* Finally (hope so) fix issues with closure. Add new docstring each time

* coverage for UndefinedType

* Checking signature more simple and obvious way

* Changed doc caption to simple message, used Undefined, merge conflicts

* Compatibility with py3.6

* Add changes/ file

* Ah, that space... Reformatted and ready to go!

* Update pydantic/main.py

Co-Authored-By: Samuel Colvin <samcolvin@gmail.com>

* Update pydantic/main.py

Co-Authored-By: Samuel Colvin <samcolvin@gmail.com>

* Fix signature for properties declared as fields

* Sort imports

* Add comments

* Generate BaseModel signature instead of __init__ signature

* Fixed imports

* Minor improvements from review

* Add docs for model signature

* Delete unused imports

* Fix formatting in tests

* Remove inspect imports from top level

* Update docs/examples/models_signature.py

Co-Authored-By: Samuel Colvin <samcolvin@gmail.com>

* Add missing import

* Remove notes from doc

* change hypothesis-auto mention to hypothesis

* Use None as slice end instead of len()

* tweak generate_model_signature

* improve docs

* Revert af3dd4d, add fields to custom init only if var_kw declared

Co-authored-by: Samuel Colvin <samcolvin@gmail.com>
2020-02-27 17:35:51 -05:00
David Montague dbc044e357 Add support for nested generics (#1104)
* Add support for nested generics

* Allow instantiation of unparameterized generics

* Add better more partial instantiation tests

* Add changes

* Add docs
2020-01-10 21:06:52 +00:00
Samuel Colvin c37ac1c5e6 Warnings for optional required, fix #1047 (#1048) 2019-12-02 12:47:56 +00:00
Sebastián Ramírez d9bbb05a16 Implement Optional required (#1031)
* Implement Optional required, when creating a ModelField(required=True), make it persist

* Add test for nullable required

* Improve formatting of Undefined custom object

* Refactor field infer/creation with Undefined to make it idempotent

Needed for when _type_analysis is re-run in Generics

* Add PR changes

* Increment/update tests with code review

* Update/refactor Undefined implementation with code review

* Fix BoolUndefined as string type for mypy, not runtime

* Add docs about required Optional

* Add explicit tests for Any

* Apply code review requested changes

* move tests out of test_validators.py
2019-11-28 16:48:33 +00:00
dmontagu 6564bbb4ce Add parse_as_type function (#934)
* Add parse_as_type function

* Add changes

* Incorporate feedback

* Add naming tests

* Fix double quotes

* Fix docs example

* Reorder parameters; add dataclass and mapping tests

* Rename parse_as_type to parse_obj, and add parse_file

* Incorporate feedback

* Incorporate feedback

* use custom root types
2019-11-25 12:55:15 +00:00
dmontagu 62bc930f57 Add support for mapping types as custom root (#958)
* Add support for mapping types as custom root

* Incorporate feedback

* Add changes

* Incorporate feedback

* Add docs and tests

* Fix linting issue

* Incorporate more feedback

* Add more specific match
2019-11-25 12:19:41 +00:00
Samuel Colvin 17b5ff42c1 renaming docs examples (#972)
* renaming docs examples

* tweaks
2019-11-07 14:40:44 +00:00
Samuel Colvin b8bbfec670 release notes for v1 (#918)
* release notes for v1

* uprev and tweaks

* Apply suggestions from code review

Co-Authored-By: dmontagu <35119617+dmontagu@users.noreply.github.com>

* tweak notes, add back link to old docs

* build changelog
2019-10-23 11:48:14 +01:00
Samuel Colvin 677677e536 modify behaviour of the construct method (#898)
* modify behaviour of the construct method

* change construct signature

* Add example for construct function (#907)

* add example for construct

* edit exporting_models

* typo

* add changes file

* code review changes

* fix bad copy paste

* extend example in docs

* use __field_defaults__ in construct
2019-10-23 10:49:05 +01:00
Samuel Colvin 7db098fa49 get item type in get_annotation_from_field_info (#909)
* get item type in get_annotation_from_field_info, fix #779

* check constraints are enforced

* add change

* tests for phony constraints

* rewrite get_annotation_from_field_info

* fix tests

* add constaint enforcement to docs

* fix get_annotation_from_field_info coverage

* fix linting

* update docs as per @tiangolo suggestions
2019-10-18 17:41:10 +01:00
Samuel Colvin e7227db41a Insert prints in docs. (#895)
* starting insert prints

* working exec_script

* remove prints, fix exec_examples.py

* more cleanup of examples, better model printing

* upgrade netlify runtime

* extra docs deps

* few more small tweaks
2019-10-14 16:40:25 +01:00
Samuel Colvin d0c6ec7009 deprecate Model.fields for Model.__fields__ (#883)
* deprecate Model.fields, use Model.__fields__

* correct docs
2019-10-11 11:10:02 +01:00
dmontagu beb57364d2 Lots of minor docs tweaks (#877)
* Lots of minor changes

* More tweaks

* Remove git conflicts

* suggested tweaks
2019-10-10 12:00:22 +01:00
dmontagu 09baf53dc9 Add support for custom naming schemes for GenericModel subclasses (#860) 2019-10-07 18:37:39 +01:00