Commit Graph

62 Commits

Author SHA1 Message Date
Samuel Colvin cb262daddd fix ValidationError.json() (#922) 2019-10-23 10:27:55 +01:00
dmontagu 6b5adcc977 Rename skip-defaults, and add ability to exclude actual defaults (#915)
* Rename skip-defaults, and add ability to exclude actual defaults

* Add __defaults__ and deprecation warnings

* Add note about `skip_defaults` to docs

* Incorporate feedback

* Add tests and changes

* Fix reference to .json()
2019-10-23 10:14:51 +01:00
Samuel Colvin f5cde39e75 ConstrainedList improvements, fix #913 (#917) 2019-10-21 12:15:54 +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 78921da353 better str and repr for ModelField (#912)
* better str and repr for ModelField, fix #505

* better type display, fix tests

* correct _type_display signature

* fix for python3.6 differences

* fix PyObjectStr

* fix coverage
2019-10-18 14:32:30 +01:00
Trim21 afba60f112 update docs for bool to match code (#911)
* update docs for bool to match code

* add changelog
2019-10-17 14:57:56 +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
Ivan Dmitrievsky 806eba3810 Merge init_kwargs with env variables recursively to handle nested values (#891)
* Merge init_kwargs with env variables recursively to handle nested values

This commit implements `deep_update` function that works as standard
`update` method on dicts, but also recursively updates all the nested
dict values. It allows splitting init arguments between environment
variables and in-code values, as long as they create a valid object
when merged together.

* Add entry to changes directory

* Fix CI/CD checks

* Make deep_copy not mutating, improve tests and type annotations
2019-10-15 11:24:46 +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 d381fe84c6 deprecate case_insensitive on BaseSettings config (#885) 2019-10-11 15:59:02 +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
Samuel Colvin 41d79de3a9 fix subtle issue with settings env variables (#882) 2019-10-10 13:24:50 +01:00
Samuel Colvin bd8918bfab use FutureWarning in settings so it's printed (#881)
* use FutureWarning in settings so it's printed

* fix tests

* better warning link

* change warning link
2019-10-10 13:24:23 +01:00
Koudai Aono 46db1efdfc Fix field of a type that has a default value (#880)
* fix type field

* update changes

* add testcase

* separate test for type fields
2019-10-09 14:06:15 +01:00
retnikt 6a0e5313cb Fix #867 by accepting and passing on **kwargs in ModelMetaclass.__new__ (#868)
* Fix #867 by accepting and passing on **kwargs in ModelMetaclass.__new__

pydantic.main.MetaModel.__new__ should include **kwargs at the end of
the method definition and pass them on to the super call at the end in
order to allow the special method __init_subclass__ to be defined with
custom parameters on extended BaseModel classes.

* MetaModel -> ModelMetaclass

* shrink change notes

* rename and reformat change description
2019-10-08 11:10:43 +01:00
Samuel Colvin 4762f49b36 prepare v1.0b2 2019-10-07 18:46:37 +01:00
Samuel Colvin ae34a6a733 rename allow_population_by_alias -> allow_population_by_field_name (#875)
* rename allow_population_by_alias -> allow_population_by_field_name, fix #585

* add change

* tweak PR template ☣️

* tweak Makefile
2019-10-07 18:40:01 +01:00
dmontagu 9667478376 Make strictbool typecheck as bool (#873)
* Make strictbool typecheck as bool

* Incorporate feedback

* Remove unneeded pragma: no cover
2019-10-07 18:39:09 +01:00
dmontagu 09baf53dc9 Add support for custom naming schemes for GenericModel subclasses (#860) 2019-10-07 18:37:39 +01:00
dmontagu 425fac6343 Automatically add no-cover to TYPE_CHECKING blocks (#874)
* Automatically add no-cover to TYPE_CHECKING blocks

* Add changes file
2019-10-07 18:02:34 +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 8dabb34390 Version 1 beta (#853)
* link to old docs, uprev

* generate history
2019-10-01 17:41:33 +01:00
Samuel Colvin 6e5a1363cc V0.32 merge (#852)
* fix(validate-assignment): do not validate extra fields when `vaidate_assignment` is on

* Update history

* Fix `value` vs. `value_`

* Add tests for `value` vs `value_` case

* uprev

* Fix generic required (#742)

* Fix required fields on GenericModel

* lint

* version up

* __post_init__ with inheritance, fix #739 (#740)

* Fix custom Schema on GenericModel fields (#754)

* Fix custom Schema on GenericModel fields

* Add PR#

* uprev

* Fix error messages for Literal types with multiple allowed values (#770)

* Fix error messages for Literal types with multiple allowed values

* Incorporate feedback

* update history
2019-10-01 17:22:05 +01:00
Samuel Colvin 8f29837703 small bits of cleanup (#851)
* small tweaks to main.py

* add changes

* correct ModelMetaclass name

* fix password and user on AnyUrl
2019-10-01 17:08:30 +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 6198343d9b Make history (#850)
* adding make_history.rst

* add to history

* fix on python3.6
2019-10-01 16:21:11 +01:00
Matthias 3ce16edbe2 Extend dataclass doc (#848)
* Add note detailing dataclass vs BaseModel usage

* Add changes rst describing the change
2019-10-01 15:51:37 +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
Spencer Ellinor 253983559b Support use of TypeVar on generic subclasses (#842)
* Add failing generic subclass test

* Only raise type parameter failure on base GenericModel class

* Add changes to describe PR #842

* Change the class check to use is

* Fix formatting in subclass test

* correct change
2019-09-30 14:30:14 +01:00
dmontagu cccf39e7c9 Fix raised ValidationError for model-type fields (#820) 2019-09-20 12:43:58 +01:00
Samuel Colvin 24ac05276b big performance improvement! (#819)
* big performance improvement!

* exception performance improvement

* check errors and explicit export from errors.py

* more tweaks

* fix coverage

* fix tests and remove "from e" in exceptions for performance
2019-09-18 15:00:43 +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
Hmvp dd32a43814 Fix const validations (#794)
This fixes #620 and #793
2019-09-17 18:30:58 +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
Henrik Lindgren 7704ff857e Local part of email is now case-sensitive after validation per RFC 5321. (#801)
* Test local and global part of EmailStr validation return values

* Make local part of email case-sensitive per RFC 5321

* Update changes/798-henriklindgren.rst

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

* remove case-sensitive specific tests from EmailStr
2019-09-10 11:16:44 +01:00
Oliver Bristow 830278b17b Set additionalProperties to False on Extra.forbid models (#796) 2019-09-09 10:18:12 +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
Samuel Colvin 32efbf069b dataclass import alias for export (#783)
* dataclass import alias for export, fix #781

* support --no-implicit-reexport in pydantic, add changes
2019-08-28 11:54:59 +01:00
Scott P 5015a7e48b Improve auto-generated title in JSON schemas (#772)
* Improve auto-generated title in JSON schemas

Underscore is converted to space.

* Added changes .rst file.
2019-08-21 16:49:05 +01:00
Samuel Colvin 9dee83a689 better error message for TypeError on datetime parsing (#766)
* better error message for TypeError on datetime parsing

* add change, fix tests

* reduce scope of errors caught
2019-08-21 13:45:11 +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
Samuel Colvin 5f634067da moving typing related objects into typing.py (#761)
* moving typing related objects into typing.py, fix #713

* cleanup
2019-08-21 12:49:19 +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 5e8db161b8 Preserve annotations from bases (#758)
* Preserve annotations from bases

* Incorporate feedback

* Update tests based on feedback
2019-08-21 12:45:50 +01:00
Samuel Colvin 0e8cfba713 small performance improvements to validators and fields (#763)
* small performance improvements to validators and fields

* simplify ErrorWrapper and ValidationError

* more cleanup of errors, combine test_error_wrapper.py and test_error.py

* tweak datetime_parse.py

* fix for python 3.6

* add change

* fix bug with int or float passed to datetime.time
2019-08-18 16:48:39 +01:00