Commit Graph

146 Commits

Author SHA1 Message Date
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
Tyler Wozniak 3e4c1b5714 Adding deque to valid field types (#1935)
* Adding deque to valid field types

* Added missing type example

* Fix bad copy-paste

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

* correct enum validator name

* correct enum validator name, take2

Co-authored-by: PrettyWood <em.jolibois@gmail.com>
Co-authored-by: Samuel Colvin <s@muelcolvin.com>
2020-10-25 17:52:34 +00:00
Samuel Colvin a25aba26b5 linting as a separate CI step (#2030)
* linting as a separate ci step

* CI and docs improvements

* fix docs preview

* fix docs, benchmarks fastapi tests

* fix formatting and docs build

* tweak publishing docs

* fix for new download-artifact action

* skip check tag to check docs build

* prepare for merge
2020-10-25 15:03:33 +00:00
Samuel Colvin 8ccc5708f1 remove data.json, fix #1992 (#1994) 2020-10-11 19:34:37 +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
Samuel Colvin 9c4860ce96 Valdiate arguments config (#1663)
* add `configs` to validate_arguments

* simplify `validate_arguments` and add annotation for parameter `configs`

* change double quotes to single quotes

* reformat code

* fix mypy error

* fix mypy 'maximum semantic analysis' error

* rename 'configs' > 'config_params'

* change name and usage, start tests

* prevent setting fields on custom config

* add docs and fix mypy

* tweak docs

* add change

Co-authored-by: quantpy <quantpy@qq.com>
2020-09-06 23:17:52 +01:00
Patrick Wang dca98559d5 Add conset (#1627)
* Add conset

* Add changes doc

* Fix too-long lines

* bump

* Update conset change doc formatting

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

* Robustify test_conset

* Move conlist and conset tests to test_types

Co-authored-by: Samuel Colvin <s@muelcolvin.com>
Co-authored-by: Samuel Colvin <samcolvin@gmail.com>
2020-07-03 20:51:23 +01:00
Samuel Eklund 7bd635c21c Subclass validator each item docs (#1592)
* add description of subclass each_item scenario

* add example of subclass validator with each_item

* each_item causes validator to not run when parent class has List field #1566
2020-06-27 14:51:18 +01:00
Koudai Aono 6e29848608 Add datamodel-code-generator link in pydantic document site (#1532)
* Add datamodel-code-generator link in pydantic document site.

* tweak menu

* fix blank lines

Co-authored-by: Samuel Colvin <samcolvin@gmail.com>
Co-authored-by: Samuel Colvin <s@muelcolvin.com>
2020-05-31 15:23:20 +01:00
Samuel Colvin dc094f1211 fix blank lines in docs 2020-05-31 15:05:06 +01:00
Stephen Brown II ba2cc5c557 Make assertion match message (#1533) 2020-05-31 14:57:37 +01:00
Stephen Brown II ec1dca9126 Add linting for docs/examples (#1530) 2020-05-31 14:54:12 +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
Mike Grima 28c2ac7a43 Added docs on dumping dataclasses to JSON (#1487) 2020-05-18 21:55:49 +01:00
Stephen Brown II cab6313798 Allow subclasses of known types to be encoded with superclass encoder (#1291)
* Add (failing) test for Subclass JSON encoding

* Allow subclasses of known types to be encoded with superclass encoder

* Add change file

* Add documentation, fix custom json_encoders and add unit test

Blacken doc
Fix test that worked on my machine
datetime.timestamp() is flakey?
Single quotes only

* Reduce lookups

- Remove last element in `__mro__` as it will always be `object`
- Use .get for compactness

* Regarding the loop

* Move Path and Enum into ENCODERS_BY_TYPE

Sort ENCODERS_BY_TYPE

* improve JSON docs

Co-authored-by: Samuel Colvin <s@muelcolvin.com>
2020-04-18 17:11:00 +01:00
Lance McNearney 161a12a1a1 Update constr regex example to include start and end lines (#1400)
This is due to the regex using `re.match()` which allows for only a partial match, fix #1396
2020-04-18 17:02:22 +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
Atheuz 7cc5dbeb6a document making secret types dumpable using the json method (#1328)
Co-authored-by: Lasse Gravesen <lasse.gravesen@falcon.io>
2020-04-15 22:05:43 +01:00
Stephen Brown II 13b002e97f Add datetime field to default_factory example (#1301)
* Add change file

* Add datetime field to default_factory example

Print instead of assert
Remove bad quotes
Remove bad quotes from all examples

* fix change description

* remove 'avoid-escape' from setup.cfg

Co-authored-by: Samuel Colvin <s@muelcolvin.com>
2020-03-18 20:23:42 +00:00
Michael (Misha) Salim ebb2e6c942 Use __all__ to exclude fields from all elements of a list/tuple of submodels. Raise more informative TypeError when passing bad exclude kwargs. (#1286)
* Raise informative TypeError when passing bad exclude kwargs to export

* Cleanup spurious example

* Add __all__ keyword to enable excluding fields from all members of a list/tuple of child submodels

* Add changelog

* Fix MD format inconsistencies and consolidate export tests

* Excluding from exported List of Dict fields with "__all__"

* tweaks

Co-authored-by: Samuel Colvin <s@muelcolvin.com>
2020-03-18 20:22:49 +00:00
Ondrej Kokes ddc8e5a57b Fix type annotations in examples (#1248)
* README change to make type annotations valid

* example fixed to have valid type annotations

* changes description

* Update README.md

explicit assignment for an optional field

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

* Update docs/examples/index_main.py

explicit assignment for an optional field

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

Co-authored-by: Samuel Colvin <samcolvin@gmail.com>
2020-03-04 17:26:11 +00: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
Samuel Colvin e3243d267b upreving packages, fix python 3.7 docs generation (#1271) 2020-03-01 13:34:35 +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
Samuel Colvin 6914410f38 Validation Decorator (#1179)
* starting validation_decorator

* correct skip_pre_38

* fix coverage and type hints

* mypy tests and move to class based decorator

* 3.6 fix, prevent duplicate github actions

* correct py 3.6 check

* better errors

* cleaner field names for args and kwargs

* add change and comments

* starting docs

* back to 3.7 for docs

* docs

* bump

* add async example and fix print indents

* allow type annotations as strings

* python 3.8 in docs
2020-02-05 17:27:12 +00:00
Samuel Colvin 943a8a06e5 change alias priority logic (#1178)
* fix alias priority so alias_generators don't take priority

* improve test names

* remove debugs

* Apply suggestions from code review

* more tests and allow custom alias_priority on fields

* precedence tests and docs

* tweaks and add change

* suggestions
2020-01-24 10:31:16 +00:00
James Curtin b7c0dd5b16 Support unicode and punycode when validating TLDs (#1183)
* Support unicode and punycode when validating TLDs

* Consolidate HTTP internationalization logic
2020-01-21 16:55:11 +00:00
Sebastián Ramírez aeba494388 Add support for generics with __get_validators__ (#1159)
*  Add support for generics with __get_validators__

*  Add tests for Generics with __get_validators__

* 📝 Add change note

*  Add support for Generic fields with validation of sub-types

* 📝 Add docs for arbitrary generic types

*  Add tests for generic sub-type validation

* 📝 Update change note. Generic support is not so "basic" now

* 📝 Update docs with code review

* ♻️ Update fields module with code review changes

*  Update tests from code review

* 📝 Update example for generics, try to simplify and explain better

* tweak docs example

Co-authored-by: Samuel Colvin <samcolvin@gmail.com>
2020-01-17 16:22:54 +00:00
Sebastián Ramírez 496551c854 Implement support for declaring infinite generators (#1152)
*  Implement support for infinite generators with Iterable

*  Add tests for infinite generators

* 🎨 Fix format

* 📝 Add docs for infinite generators

* 📝 Add changes file

*  Store sub_field with original type parameter to allow custom validation

* 📝 Add example for validating first value in infinite generators

* 🔥 Remove unused import in example

*  Add test for infinite generator with first-value validation

* ♻️ Update fields with code review

* 📝 Update example from code review

* 📝 Update docs and format from code review
2020-01-13 11:50:16 +00: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
John Carter cd8b504568 Pass model_class to schema_extra staticmethod (#1125)
* Pass model_class to schema_extra staticmethod

Resolves #1122

* Add changelog

* Apply suggestions from code review

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

* Fix import after rebase

* Fix test bug

* Use TypeError instead of assert as per review

* Rename var so declaration fits one one line

* tiny tweaks

Co-authored-by: Samuel Colvin <samcolvin@gmail.com>
2020-01-06 12:01:03 +00:00
pmav99 8a53350412 docs: Add docs for allow_reuse (#1135)
* docs: Remove trailing whitespace

* docs: Add docs for "allow_reuse"
2020-01-02 15:13:44 +00:00
John Carter a7ef2d5e1b Trivial - Fix comment spelling (#1114)
* Fix comment spelling

* Grammar fix

Co-Authored-By: David Montague <35119617+dmontagu@users.noreply.github.com>
2019-12-19 12:12:52 +00:00
Samuel Colvin bd72e80e94 Prevent type attributes being added to schema unintentionally (#1065)
* Prevent type attributes being added to schema unintentionally, fix #1064

* simpler boolean check

* change to __modify_schema__

* better docs

* Update docs/usage/schema.md

Co-Authored-By: dmontagu <35119617+dmontagu@users.noreply.github.com>
2019-12-11 12:01:41 +00:00
Selim Belhaouane bdc3973d90 Allow schema_extra to be a callable (#1054)
* fixes for Windows development

* Allow Config.schema_extra to be a callable
2019-12-09 11:01:17 +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
Daniel Smith c2e0082800 ByteSize conversion (#996)
* Bytesize implement to conversion

* Changelog

* Lint: changes to single quotes

* Update tests/test_types.py

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

* Update tests/test_types.py

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

* Update tests/test_types.py

Co-Authored-By: Samuel Colvin <samcolvin@gmail.com>
2019-11-14 16:22:51 +00:00
Daniel Smith b92e74d0a6 Bytesize (#977)
* ByteSize object

* Human readable format

* Lint, tests, and docs

* Update pydantic/errors.py

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

* Update pydantic/types.py

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

* Update pydantic/types.py

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

* Allows human readable decimal descriptor

* Review comments

* Less verbose testing

* ByteSize docs

* Reworks valid units

* Missing type

* tweak tests
2019-11-09 12:39:02 +00:00
Alexander Hirner c188b3fba8 Feature/dataclass schema defaults (#980)
* default dataclass field from default_factory

* silence mypy regarding issue 708

* test dataclass factory function default

* test default factory ending up in schema

* add changes md

* add docs for dataclass default factory and basemodel access

* fully print default factory schema
2019-11-09 12:29:15 +00:00
Samuel Colvin 17b5ff42c1 renaming docs examples (#972)
* renaming docs examples

* tweaks
2019-11-07 14:40:44 +00:00
Samuel Colvin 1d3f7824ec Fix broken Any and TypeVar behaviour (#962)
* tests for broken Dict behaviour

* fix Any, support TypeVar

* change type of field.type_

* add docs and example for TypeVar
2019-11-07 12:31:26 +00:00
dmontagu 0c18619769 Mypy plugin (#722)
* Add mypy plugin

* Make all arguments optional for BaseSettings

* Get test coverage up

* Add changes

* Add type-checking for BaseModel.construct, and checking for from_orm

* Fix formatting and linting

* Fix the build

* Heavy refactor of plugin and mypy tests

* Make linting pass

* Handle dynamic aliases

* Better organize plugin code

* Add docs

* Add support for error codes

* Fix minor docs typo

* Rename config settings, add docstrings, and incorporate other feedback

* Incorporate feedback

* Update docs, remove dataclasses for cython

* fix mypy example
2019-10-31 13:19:01 +01: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 ed7b216e5f Change alias precedence to prefer child models (#904)
* Change alias precedence to prefer child models

* add docs about alias precedence

* correct change
2019-10-17 10:58:28 +01:00