Commit Graph

81 Commits

Author SHA1 Message Date
Samuel Colvin cb262daddd fix ValidationError.json() (#922) 2019-10-23 10:27:55 +01:00
Samuel Colvin f5cde39e75 ConstrainedList improvements, fix #913 (#917) 2019-10-21 12:15:54 +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 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 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
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
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
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 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
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
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
dmontagu f881d4f30c Make .json() work for EnumError (#697)
Make .json() work for EnumError, fix #696
2019-07-31 09:12:18 +01:00
dmontagu b702eb8738 Update error message for enum validator (#673)
* Update error message for enum validator

* Update history
2019-07-24 10:53:10 +01:00
Justin DuJardin bc60014518 Add better support for floating point multiple_of values (#652)
- modulo doesn't work with floating point values in many cases, e.g. `0.3 % 0.1 == 0.09999999999999998`
 - port implementation from: https://github.com/tdegrunt/jsonschema/issues/187#issuecomment-320664251
 - add tests for int/float multiple_of values
 - update history with pr/author
2019-07-23 16:41:11 +01:00
dmontagu 18d4b2bb2a Make schema work for Literal and NewType (#649)
* Make schema work for Literal and NewType, fix #646

* Fix test when typing_extensions not installed

* Make literal values fetching 3.6 compatible

* Rework to get around issues with Literal in python 3.6

* Make cython-compatible

* Use union for multiple allowed literal values

* Minor simplification of values-gathering

* Updated history
2019-07-15 20:06:35 +01:00
dmontagu 3ee54ed2bb Add support for Literal annotation (#582)
fix #561

* Add support for Literal annotation

* Updated requirements.txt

* incorporating feedback

* skip typing_extensions tests if not installed

* missed a spot

* address feedback

* Make work with python 3.6

* Work for *both* 3.6 and 3.7

* incorporate feedback

* fixed naming and quotes

* Trying to fix LGTM bot issue
2019-06-25 10:33:21 +01:00
Samuel Colvin 461b852e4e enforcing single quotes (#612)
* enforcing single quotes

* update history
2019-06-21 12:32:03 +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
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
dmontagu af26f7f181 Fix issue with unspecified generic type (#554)
* Fix issue with unspecified generic type, fix #550

Seems to solve #550

With this change, models with bare `List` or `Dict` as a typehint still validate for type agreement, but don't validate the type of the parameters.

I'm not sure this is the "right" fix (I don't know the implications of ignoring TypeVars like this), but considering how simple it was I figured I'd at least share.

* Update validators.py

Found this discussion: https://github.com/samuelcolvin/pydantic/issues/545; `lenient_issubclass` does seem to fix it.

* Update validators.py

Hacky solution to prevent no validator exception. Maybe there's a better way?

* Tests pass and PR checklist done

* Check sooner

* Block empty list from dict constructor

* Removed modifications to dict_validator
2019-05-29 19:35:16 +01:00
Samuel Colvin 66ce99e4f0 Azure Pipelines - tests for windows (#538)
* add azure-pipelines.yml

* fix install command

* skip some tests on windows
2019-05-23 10:30:32 +01:00
Vitaly R. Samigullin fe72ba13f4 Tuple ellipsis (#512)
* Variable size tuple support added, fix #495

* Minor fixes and tests added (#495)

* Variable length tuple refactored after a code review (#495)
2019-05-11 16:10:02 +01:00
Atheuz 449661b8cc fix: serialize secrets to json. (#465)
* fix: serialize secrets to json, fix #462

* feat: adjust documentation for secretstr.

* feat: undo unnecessary changes. keep tests.

* fix: tests were broken, now they're fixed again.

* feat: add display fn to SecretStr and SecretBytes, to be used for json output.

* fix: minor typo.

* fix: last few comments.
2019-04-11 19:32:28 +01:00
Atheuz 4a8faca42e feat: add SecretStr and SecretBytes. (#452)
* feat: add SecretStr and SecretBytes.

* chore: update HISTORY.rst

* fix: file permissions were incorrect.

* feat: lint, format, fix comments.

* feat: changed inner type of SecretBytes in the schema to string as there is no bytes type in json.

* feat: remove format from secret str and secret bytes.

* feat: fix schema mapping.
2019-04-04 12:14:47 +01:00
Vitaly R. Samigullin 9e12674827 PyObject callable values (#440)
* Support callable as PyObject field

* Add unittests for PyObject callable values

* Update HISTORY.rst

* PyObject minor fixes after code review (#409)
2019-04-04 10:00:55 +01:00
Nikita Leybovich 3a33d8db10 IntEnum support (#444)
* IntEnum support

* Update HISTORY.rst
2019-04-01 15:52:24 +01:00
Vitaly R. Samigullin 42bc8e4b43 Sequence support (#428)
fix #304

* Sequence support added

* Unittests for sequence added

* Fix HISTORY

* Sequence validation simplified

* Fix type conversion for Sequence
2019-03-29 10:17:23 +00:00
Yaraslau Zhylko 37855aa90c fix typo in NoneIsNotAllowedError message (#414)
* fix typo in `NoneIsNotAllowedError` message

* Add HISTORY.rst entry
2019-03-07 13:33:58 +00:00
Stephen Brown II 61e758965c Add multiple_of attribute to constrained numerics (#371)
* Add multiple_of attribute to constrained numerics

* Update HISTORY.rst

* make format

* Change limit_value -> multiple_of
2019-02-03 17:13:27 +00:00
Nikita Grishko 145f04cb5d add `ConstrainedBytes and conbytes` types #315 (#357)
fix #315
2019-01-17 13:57:49 +00:00
Samuel Colvin 0d5cd3bce5 better import errors, fix #309 (#336) 2018-12-27 19:37:53 +00:00
Samuel Colvin c725a4a5e5 prevent validators being called repeatedly after inheritance (#327)
* prevent validators being called repeatedly after inheritance

* fix linting

* more tests
2018-12-25 22:33:18 +00:00
Samuel Colvin 9ff946d2fa PyObject = None, and Pattern (#306)
* PyObject = None, fix #305

* history formatting on pypi

* fix history rendering in setup

* allow Pattern validation, fix #303

* fix for python3.7

* fix linting

* proper processing for regex pattern errors
2018-11-18 16:11:29 +00:00
Samuel Colvin 15850a43c5 moving to black (#287)
* moving to black

* put back flake8

* remove isort option

* putting back isort

* uprev pycodestyle

* remove black from docs/examples

* tweak parse.py
2018-11-15 11:30:07 +00:00
Evghenii Goncearov c31b8d6719 Json type (#214)
* Json type

* Sort imports

* one more unsorted import

* Changed the way Json type is defined

* Fix Function is too complex (C901) warning

* Fixed remarks

* Fix additional remarks

* Additional test

fix #195
2018-07-10 15:38:28 +01:00
Samuel Colvin c0413c8896 list, set, tuple validation (#225)
* list, set, tuple validation, fix #202

* update HISTORY.rst
2018-07-04 16:32:42 +01:00
Nikita Grishko c002c490ae add `NewType` support #115 (#223)
* add ``NewType`` support #115

* updated history

fix #115
2018-07-04 16:11:55 +01:00
Nikita Grishko f8c1a350f4 add `FilePath and DirectoryPath` types #10 (#208)
* add ``FilePath`` and ``DirectoryPath`` types #10

* review fixes

* improve tests

* simplify errors
2018-06-28 11:04:00 +01:00
clip d2745065f5 fix typo (#207)
* fix typo

* fix test
2018-06-24 17:52:56 +01:00
Nikita Grishko 4f19d2b94a Strict validation of list, set and tuple (#86) (#200)
* Strict validation of `list`, `set` and `tuple` (#86)

* review fixes
2018-06-13 19:11:01 +01:00
Samuel Colvin f0f9de5f96 improve docs on error handling (#198)
* improve docs on error handling

* change ValidationError signature

* cleanup

* rename _raw_errors > raw_errors

* improve _display_error_type_and_ctx
2018-06-11 13:06:50 +01:00
Jasper Schulz 3ef595556c Added le and ge bounds to constrained numerics. (#194)
* Added `le` and `ge` bounds to constrained numerics.

* Addressed comments.

* Addressed @Gr1N comments.

* Removed comment.
2018-06-08 10:32:26 +01:00
Samuel Colvin e57f8c4725 correct and complete #188 (#193) 2018-06-07 09:19:02 +01:00
Samuel Colvin 95aba150b2 gt, lt, (#188)
* gt, lt, fix #176

* change test names
2018-06-02 20:53:10 +01:00
Samuel Colvin 31f5f9c267 Cleanup 183 (#187)
* fix coverage

* use change_exception

* simplifying get_exc_type

* improve to_snake_case

* improve change_exception

* remove to_snake_case completely

* correct comment
2018-06-02 18:08:07 +01:00
Nikita Grishko 4f4e22ef47 Error context and message (#183)
* POC of error context and message

* Move type errors to the `errors.py` module; Change errors interface a bit

* Rename `.as_dict()` to `.dict()`

* Fix `PydanticErrorMixin` constructor

* Rename `exceptions.py` to `error_wrappers.py`

* Do not include nullable `ctx`

* Fix tests

* Added `int_validator`; Added `IntegerError`

* Added `float_validator`; Added `FloatError`

* Get rid of `__mro__` in prior of `exc.code`

* Removed `min_number_size` and `max_number_size` from config (#174)

* Added `NumberMinSizeError` and `NumberMaxSizeError`

* Added `NoneIsNotAllowedError`

* Added `EnumError`

* Added `path_validator`; Added `PathError`

* Added `DictError`

* Added `ListError`

* Added `TupleError`

* Added `SetError`

* Added `datetime` related errors

* Added `bytes` and `str` related errors

* Added `SequenceError`

* Improved code coverage

* Display error context in string representation of validation error

* Redefine error message templates using config

* Review fixes

* Updated changelog
2018-05-31 14:35:38 +01:00
Nikita Grishko 31683f8dc4 Errors format (#179)
* Get rid of `track` in errors

* Move `display_as_type` func into utils module

* Get rid of error as `namedtuple`

* Renamed `Error.index` to `Error.loc`

* New way to get error type

* New way to get error message

* New errors format

* Renamed `flatten_errors` property to `flat_errors`

* `__slots__` for `Error` and `ValidationError`

* `loc` as `tuple`

* Tests

* Review fixes

* `flatten_errors` as generator
2018-05-23 14:50:04 +01:00
Nikita Grishko 99d7eafa61 add `Decimal, ConstrainedDecimal and condecimal` types #170 (#175) 2018-05-10 12:11:45 +01:00