Commit Graph

48 Commits

Author SHA1 Message Date
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
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
dmontagu 6c0f4f31d1 Test mypy integration with pytest (#735)
* Test mypy integration with pytest

* Fix for without deps

* Fix filenames issue

* Remove python run in external-mypy

* Update changes

* Remove external-mypy
2019-08-17 12:59:11 +01:00
Koudai Aono 08c6af8ae2 add documentation for PyCharm Plugin (#750)
* add documentation for PyCharm Plugin

* add a change document for a history

* Delete typing.py

* update documents

* Apply suggestions from code review

Co-Authored-By: Samuel Colvin <samcolvin@gmail.com>
2019-08-16 11:37:13 +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
dmontagu 321cde0c88 Include all annotated fields in order (#715)
* Include all annotated fields in order

* Update docs and changes

* fix field ordering

* update change info

* fix coverage
2019-08-12 12:05:22 +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
Samuel Colvin 5837acb288 test demonstrating internal ValidationError (#738)
* test demonstrating internval ValidationError

* fix #736
2019-08-11 14:14:02 +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
Samuel Colvin 72bada8ca8 add change, and tweak change format 2019-08-06 16:37:38 +01:00
Samuel Colvin 9c8bba71c6 Preparation for Version 1 2019-08-06 16:19:38 +01:00