Commit Graph

110 Commits

Author SHA1 Message Date
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
Ashton Shears b1e61b415a change secret types example (#890)
* change secret types example

* add changes file

* add address review comments

* remove redundant str() call
2019-10-14 18:00:37 +01:00
Samuel Colvin c3098a30cf Consistent __repr__ and __str__ methods for all types (#884)
* Consistent __repr__ and __str__ methods for all types

* add change description

* devtools integration and feedback on repr methods

* fix Color repr

* tests for truncate

* add devtools section to docs

* tests for devtools

* ValidationError inheriting from Representation

* fix imports

* tweaks

* tweak docs

* exec_examples.py integration with __repr__ changes
2019-10-14 17:37:04 +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 f3dd39c1bb Few more tweaks to docs (#879) 2019-10-10 12:10:39 +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
Samuel Colvin 33b7d52d31 moving docs to mkdocs (#856)
* moving docs to mkdocs

* transfering readme to md and more

* fixing build

* splitting usage.md

* improving schema.md and index.md

* fix make_history.rst

* models intro

* working on data conversation and required fields

* more fixes to models.md

* list all standard types supported

* list of pydantic types

* tweaks

* update links in code

* Apply suggestions from code review

incorporate @dmontagu's suggestions.

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

* Apply suggestions from code review

more missed suggestions.

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

* Apply suggestions from code review

more corrects.

* cleanup

* Field order warning

* fix and regenerate benchmarks

* format examples better, cleanup

* improve schema mapping table

* correct highlighting file types in schema.md

* add redirects in javascript

* add logo
2019-10-07 17:19:01 +01:00
Samuel Colvin 9a5b411016 change how env variables work with settings (#847)
* change how env variables work with settings, fix #721

* inheritance and alias warnings

* update docs

* tweak env_settings.py
2019-10-01 16:32:02 +01:00
Samuel Colvin 12f4e0d082 rename Schema to Field (#824)
* rename Schema to Field

* add Schema function with deprecation warning

* mypy tests and other tweaks

* tweaks and cleanup

* Update pydantic/fields.py

Co-Authored-By: Sebastián Ramírez <tiangolo@gmail.com>
2019-09-30 17:49:59 +01:00
Samuel Colvin 1d0d98ba19 Root validators (#817)
* root validators and rename __obj__ -> __root__

* implement root validation

* tweak Validator

* dataclass and generic tests, docs

* repeat and signature checks

* fix inheritance

* tweaks tests and var names

* improvements to 'from_orm' to work better with root validators (#822)

* improvements to 'from_orm' to work better with root validators

* cython compatibility and tweaks

* tweak config order

* added test for derived classes using custom getter_dict config (#833)

* added test for derived classes using custom getter_dict config

* fix linting

* fix formatting

* cleanup
2019-09-30 17:19:44 +01:00
Samuel Colvin 973de05a01 custom json (de)serialisation (#823)
* custom json (d)encoders, fix #714

* add docs
2019-09-30 14:34:30 +01:00
Zaar Hai 6f97c0f9f7 Fixed example with datetime JSON encoder (#846) 2019-09-30 14:08:41 +01:00
Samuel Colvin 16263bafea None behaviour (#803)
* tweaks to None behaviour

* prevent sub_fields for Optional fields by default

* rewrite None validation

* rename whole > each_item on validators

* cleanup processing of the Json type

* fix schema coverage and cleanup

* tweak validate_model

* change and docs

* fix validators on optional fields

* coverage

* remove is_none_validator

* minor performance improvements to ErrorWrapper

* fix coverage

* fix PaymentCardNumber

* undo schema changes, fix

* tweak validators
2019-09-18 11:38:21 +01:00
Stephan Lanfermann 1b467da11f Added generic approach to strict type checking for constrained types (#799)
* Added generic approach to strict type checking for constraint types
- Use the arbitrary validator to build strict validators for ConstrainedInt, ConstrainedFloat, ConstrainedStr
- Make StrictStr a derived class of ConstrainedStr
- Add tests for new strict cases for ConstrainedInt and ConstrainedFloat

* - Created StrictInt and StrictFloat subclasses and exported them
- Changed strictness tests to use these new subclasses

* - Added section for Strict Types to docs

* - Added changes file

* Update docs/index.rst

Co-Authored-By: Zaar Hai <haizaar@users.noreply.github.com>

* Update docs/index.rst

Co-Authored-By: Zaar Hai <haizaar@users.noreply.github.com>

* - Create validators for strict int and float
- Make ConstrainedInt and ConstrainedFloat use those validators instead of abusing arbitrary type validator for strictness
- Prevent double validaton of same conditions by only yielding either the strict or non-strict type validator for for those classes

* Changed strict int and float tests to alos match for exception message in invalid cases

* - Removed obvious note about lack of ConstrainedBool
- Added example for strict type usage
- Added note about caveats for StrictInt and StrictFloat

* Update pydantic/validators.py

faster method to check if a value is boolean for strict int validator

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

* - Removed StrictBool part from Boolean section of docs
- Moved the Strctbool code example into strict_types.py example file

* - Changed behavior of strictness for COnstrainedStr to match that fo other constrained types

* - Actually make ConstrainedStr use the correct validator for strictness
2019-09-17 12:38:51 +01:00
Matin Tamizi 0c5793770b PaymentCardNumber type (#790)
* initial proposal of payment card validation #788

* some cleanup for PaymentCardNumber #788

* fix linting issues

* tests and more robust errors #788

* fixed linting

* fixing mypy errors

* let's try this to make mypy work

* make consistent with cpython tests

* avoid using __new__

* use __init__ instead of properties

* clean up PaymentCardNumber.__init__

* use ClassVar where applicable

* add to changes/

* turns out this is never used

* get brand for other

* clean up a bit

* make PaymentCardNumber private

* use if/else to make faster in cython

* card_number => card number in errors

* make it clearer in the tests which exception is being raised

* parameterize tests for PaymentCardNumber

* lint

* clean up merge mistake from earlier

* fix mypy test error

* take out commented line

* update comment since code is moved

* docs for PaymentCardNumber

* clean up docs for PaymentCardNumber

* var name that makes more sense
2019-09-17 10:33:11 +01:00
Timon Ruban f08fd2fee7 Add support for Type[T] typehints when arbitrary_types_allowed==True. (#808)
* Add support for Type[T] typehints when arbitrary_types_allowe==True.

* Add documentation.

* Let black do its magic.

* Ignore mypy warning - see here: https://github.com/python/mypy/issues/3060

* Prettify docs.

* Change Changelog.

* Refactor and simplify check for Type[T].

* Black again. ^^ - Really need pre-commit hooks.

* Update pydantic/validators.py

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

* Rename arbitrary_class to class.

* Black.

* Add type hints.

* Make private function public.

* Add support for bare Type.

* Black again.

* Update docs.

* CO_ct not meant for export.

* Fix get_class for Python3.6

* Update error message of ClassError.

* Use relative import.

* Incorporate typing feedback (both versions are fine with mypy).

* Move from issubclass to lenient_issubclass.

* correct docs
2019-09-16 10:42:40 +01:00
Samuel Colvin 79017111aa new URL parsing (#755)
* new URL parsing, fix #603, fix #541

* AnyUrl parts and more tests

* more coverage and db DSNs

* remove DSN methods

* tests for urlstr

* remove debug

* make AnyStr a subtype of str

* fix with cython

* rearranging networking code

* allowing international domains, cleanup

* support international domains

* better URL builder

* allow underscores in subdomains and domains

* tests for json and schema, max length

* urlstr > stricturl

* updating docs

* tweak docs examples

* tweak docs
2019-09-02 11:37:33 +01:00
Daniel Petti aa5e8c60b7 Feature/frozenset support (#762)
* Better error for unsuported "typing" objects.

Fixes #745

Add a better error message for fields with types from the typing
module that are not directly supported by Pydantic. Previously,
it caused a cryptic assertion failure.

* Add support for frozenset fields.

Also provide an example of their usage.

Fixes #745

* Address review comments.

Fixes #745

* use equals not "is" for int comparison.
2019-08-21 13:13:46 +01:00
dmontagu 756454fb58 Change defaults for BaseSettings (#747)
* Change defaults for BaseSettings

* Update docs and fix build

* Minor documentation fixes

* Fix lowercase issues

* Update docs and fix build

* Fix formatting

* Try with monkeypatched test

* Fix doublequotes

* Change case_insensitive to case_sensitive

* more change details.
2019-08-21 12:48:28 +01:00
dmontagu 65d838aa88 Serialize only __root__ value (#752)
* Serialize only __root__ value, fix #730

* Add changes and fix docs

* Clean up root model docs

* Update docs/index.rst

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

* Update docs/index.rst

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

* Rename variable

* fix rst in change description
2019-08-17 18:58:32 +01:00
dmontagu 27bb336545 Fix broken examples (#753)
* Fix broken examples

* Update changes
2019-08-17 13:03:53 +01:00
Raphael de Carvalho Almeida 5b5451c02e Added initvars support to post_init_post_parse (#748)
* Added initvars support to post_init_post_parse

* Update change log with PR number

* Add practical initvars example to tests

* Update documentation
2019-08-16 09:36:56 +01:00
Abdussamet Koçak f41d5dca3c Support assert statements inside validators (#653)
* Support assert statements inside validators

* Add a validator example that uses assert

* Add warning about consequences of using -O optimization flag

* Fix a typo

* Fix incomplete validator

* Extend exception name generation

* Improve tests

* Clarify pytest behaviour

* handle assertion error name, fix build

* Address feedback

* docs cleanup

* Incorporate feedback

* fix quotes
2019-08-15 12:06:21 +01:00
Samuel Colvin 82ef45c890 alter the behaviour of dict(model) so that sub-models are nolonger converted to dictionaries (#733)
* fix iteration to not convert to dict by default

* add change

* remove extra newline
2019-08-12 11:31:35 +01:00
dmontagu 72edca7532 Make bool_validator strict (#617)
* Make bool_validator strict

* incorporate feedback

* Add RelaxedBool

* Fix position in schema.py

* update BoolError message

* Incorporate feedback

* Update history

* Add changes

* Update docs/index.rst

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

* Update docs/index.rst

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

* Update tests/test_types.py

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

* Incorporate feedback

* Update booleans.py

* Remove RelaxedBool

* tweak docs and update changes to new format
2019-08-10 12:00:29 +01:00
Sebastián Ramírez 3cb52b94d2 Fix double quotes to single quotes 2019-08-05 09:47:15 -05:00
Sebastián Ramírez a8ab92f382 Add example and docs for schema_extra in Config 2019-08-05 09:45:37 -05:00
Arseny Boykov 74768c1535 Add advanced exclude and include support for dict, json and copy (#648)
* Add advanced exclude support for dict, json and copy

* Add advanced exclude support for dict, json and copy

Add new version section (v0.31)

* Add advanced include support, add more tests, improve code style
Rename ValueExclude to ValueItems and move it to utils
Use old logic to calculate keys, but still exclude it in _iter

* Add more tests for ValueItems

* Removed update arg check in _calculate_keys for return None
This will increase speed when no include or exclude given and skip_defaults is False

* Fix formatting, remove duplicate imports

* Add # pragma: no cover to 'if TYPE_CHECKING:' block

* tweaks and coverage

* fix history

* Add docs

* tweak docs
2019-07-24 09:58:38 +01:00
dmontagu 4c9ee486d8 Add literal docs (#651)
* Add literal docs

* Update history

* Incorporate feedback

* fix history
2019-07-23 16:40:28 +01:00
Koudai Aono e4b285a0cd support custom root types (#628)
* support custom root types

* update HISTORY.rst for costom root types

* fix invalid arguments case

* remove the keyword argument of "__root__" in __init__
add a keyword argument of "__root__" in parse_obj
fix documents
create a method for cheking valid field name

* fix parse_obj

* Update docs/index.rst

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

* Apply suggestions from code review

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

* add type cheking for custom root type

* Update docs/index.rst

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

* Update index.rst
2019-07-06 09:52:42 +01:00
Arseny Boykov 010ba38dc1 Add alias_generator (#622)
* Added alias_provider

* Update HISTORY.rst (+ add alias_provider support #622 by @MrMrRobat)

* Rename alias_provider —> alias_generator
Move docs to config section, reformat example
Separate test_alias_generator

* Update docs/index.rst

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

* Update docs/index.rst

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

* Update docs/index.rst

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

* Fix conflict between dictionary field config in Config.fields and Config.alias_generator

Add one more condition for applying alias_generator

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

* Add test for using alias_generator with field schema
2019-07-02 12:13:06 +01:00
dmontagu b84df079a7 Add generic functionality (#595), fix #556
* Added generic functionality

* Skip tests in python 3.6

* double quote -> single quote

* Simplified, with more comprehensive tests

* double quote -> single quote

* Remove unintentional file

* Add caching

* don't cythonize generics.py

* Make work with mypy

* Remove __parameters__

* double quote -> single quote i'll remember one day

* More cleanup and validation

* Removed unwanted file

* A little more cleanup, and finish the PR

* Add proper inheritance

* Added note about inheritance to docs

* Added error for double-parameterizing

* Should build for python3.7

* Works with both 3.6 and 3.7

* Fixed bug with caching for single argument

* handle __name__ for generic models

* double quote -> single quote

* Updated error messages
2019-06-19 11:22:06 +01:00
Hmvp 1c45373f80 Add conlist type (#583)
* Add conlist type

* Fix cython issue

* Update pydantic/fields.py

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

* Update pydantic/types.py

Co-Authored-By: Samuel Colvin <samcolvin@gmail.com>
2019-06-19 11:03:31 +01:00
Adamos Kyriakou 84820bdede Clarification around usage of Union (#594)
* Added two code examples on the correct and incorrect usage of `Union` in type annotations.

* Updated documentation.

* reST fix.

* Update docs/examples/union_type_incorrect.py

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

* Update docs/examples/union_type_incorrect.py

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

* Update docs/examples/union_type_incorrect.py

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

* Update docs/examples/union_type_correct.py

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

* PR comments.

* Updated `HISTORY.rst`.

* Update docs/index.rst

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

* Update HISTORY.rst

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

* Update docs/index.rst

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

* Update docs/index.rst

Co-Authored-By: Samuel Colvin <samcolvin@gmail.com>
2019-06-15 14:05:47 +01:00
cazgp eb1e640525 StrictBool (#580)
* StrictBool

StrictBool only allows booleans to be parsed. Any other value, no matter
its truthiness, is rejected.

* Fix type of `validate`

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

* " => '

* Update the exotic docs with StrictBool

* Fix error message

* Improve docs

* tweak docs.
2019-06-06 15:18:21 +01:00
Samuel Colvin 3dfae21208 ORM mode: Add support for arbitrary class instances (#562)
* Support ORM objects to 'parse_obj', replace #520

* switch to GetterDict and orm_mode

* tweaks

* update docs

* split tests and add @tiangolo's suggestion

* split tests and add @tiangolo's suggestion

* fix coverage
2019-06-06 11:29:09 +01:00