Commit Graph

279 Commits

Author SHA1 Message Date
Samuel Colvin bbdc8e8038 add test_init_inspection 2019-08-05 11:35:49 +01:00
Arseny Boykov f01cedca14 Merge branch 'master' into __dict__-instead-of-__values__ 2019-08-05 12:58:46 +03:00
Samuel Colvin 7ace58cad8 Merge branch 'master' into type-in-validation-error 2019-08-05 10:37:42 +01:00
MrMrRobat bbf0b4bfbe Add __values__ property with deprecation warning and test for it 2019-08-03 18:05:17 +03:00
dependabot-preview[bot] a3df3aa314 Bump flake8-quotes from 2.0.1 to 2.1.0
Bumps [flake8-quotes](https://github.com/zheller/flake8-quotes) from 2.0.1 to 2.1.0.
- [Release notes](https://github.com/zheller/flake8-quotes/releases)
- [Commits](https://github.com/zheller/flake8-quotes/compare/2.0.1...2.1.0)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2019-08-02 06:39:16 +00:00
dmontagu f881d4f30c Make .json() work for EnumError (#697)
Make .json() work for EnumError, fix #696
2019-07-31 09:12:18 +01:00
dependabot-preview[bot] b58f31dfd9 Bump coverage from 4.5.3 to 4.5.4 (#695)
Bumps [coverage](https://github.com/nedbat/coveragepy) from 4.5.3 to 4.5.4.
- [Release notes](https://github.com/nedbat/coveragepy/releases)
- [Changelog](https://github.com/nedbat/coveragepy/blob/master/CHANGES.rst)
- [Commits](https://github.com/nedbat/coveragepy/compare/coverage-4.5.3...coverage-4.5.4)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2019-07-30 10:51:41 +01:00
dependabot-preview[bot] 99dc5c1c83 Bump cython from 0.29.12 to 0.29.13 (#694)
Bumps [cython](https://github.com/cython/cython) from 0.29.12 to 0.29.13.
- [Release notes](https://github.com/cython/cython/releases)
- [Changelog](https://github.com/cython/cython/blob/master/CHANGES.rst)
- [Commits](https://github.com/cython/cython/compare/0.29.12...0.29.13)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2019-07-29 10:37:01 +01:00
dependabot-preview[bot] cb81ca66b2 Bump cython from 0.29.11 to 0.29.12 (#689)
Bumps [cython](https://github.com/cython/cython) from 0.29.11 to 0.29.12.
- [Release notes](https://github.com/cython/cython/releases)
- [Changelog](https://github.com/cython/cython/blob/master/CHANGES.rst)
- [Commits](https://github.com/cython/cython/compare/0.29.11...0.29.12)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2019-07-25 18:52:55 +01:00
dependabot-preview[bot] 85f1016c4a Bump pytest from 5.0.0 to 5.0.1 (#688)
Bumps [pytest](https://github.com/pytest-dev/pytest) from 5.0.0 to 5.0.1.
- [Release notes](https://github.com/pytest-dev/pytest/releases)
- [Changelog](https://github.com/pytest-dev/pytest/blob/master/CHANGELOG.rst)
- [Commits](https://github.com/pytest-dev/pytest/compare/5.0.0...5.0.1)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2019-07-25 18:17:39 +01:00
dependabot-preview[bot] f55a633296 Bump mypy from 0.711 to 0.720 (#686)
Bumps [mypy](https://github.com/python/mypy) from 0.711 to 0.720.
- [Release notes](https://github.com/python/mypy/releases)
- [Commits](https://github.com/python/mypy/compare/v0.711...v0.720)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2019-07-25 18:17:27 +01:00
dependabot-preview[bot] 3dca559e82 Bump flake8 from 3.7.7 to 3.7.8 (#685)
Bumps [flake8](https://gitlab.com/pycqa/flake8) from 3.7.7 to 3.7.8.
- [Release notes](https://gitlab.com/pycqa/flake8/tags)
- [Commits](https://gitlab.com/pycqa/flake8/compare/3.7.7...3.7.8)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2019-07-25 18:17:13 +01:00
David Montague 8135f470e4 Incorporate feedback 2019-07-25 00:15:54 -07:00
David Montague 20619ea901 Add type name to ValidationError error message 2019-07-25 00:05:57 -07:00
Arseny Boykov fae3588f42 Add Config.keep_untouched for custom descriptors support (#679)
* Add Config.keep_untouched for custom descriptors support

* Update HISTORY.rst

* Separate test

* Fix tests

* Update pydantic/validators.py

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

* Update HISTORY.rst

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

* Rename TYPE_BLACKLIST -> UNTOUCHED_TYPES, fix tests and formatting

* Update docs/index.rst

Co-Authored-By: Samuel Colvin <samcolvin@gmail.com>
2019-07-24 16:33:49 +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
dmontagu b09e6977b9 Bugfix for generic types with parameterized generic fields (#672)
* Bugfix for generic types with parameterized generic fields

* Update history

* Skip new tests in python3.6
2019-07-24 10:52:44 +01:00
euri10 1e83ac5137 Color schema (#666)
* First attempt at adding Color in schema() generation

* Lint

* Add history

* Make docs pass

* Added format color

* Format color

* Making history...:)
2019-07-24 10:52:05 +01:00
Arseny Boykov 1b4c1a884c Fix alias_generator and field config conflict (#658)
* Fix alias_generator and field config conflict (see #645)

* HISTORY.rst update: fix alias_generator and field config conflict

* Merge HISTORY.rst with master
2019-07-24 10:32:40 +01: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
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
Levi Naden 61c8ca2f30 Re-enable nested model init calls while still allowing self (#644)
* Re-enable nested model init calls while still allowing self

This commit enables nested model `__init__` statements to be executed
while still allowing `self` as an argument.

Effectively reverses the changes from #632 while still enabling the
feature it implemented. In theory, there will still be a collision if
someone ever tried to use `pydantic_base_model/settings_init` as an arg,
but I don't know how to engineer a case where a collision would *never*
happen, I'm not sure there is one.

This commit also added a test for both BaseModel` and `BaseSettings` for
both the `self`-as-a-parameter and the nested `__init__` features since
`BaseSettings` now has the same issue as `BaseModel` since it invoked
an `__init__` with self.

I have added a comment under the `__init__` for both `BaseModel` and
`BaseSetting` since not having `self` as the first arg is such a
rarity within Python that it will likely confuse future developers who
encounter it.

The actual name of the variable referencing the class itself can be
up for debate.

* Please Lint

* Please Black

* Update from comments
2019-07-11 15:42:48 +02:00
Samuel Colvin 34f271e8fa support self argument (#632)
* support self argument, fix #629

* support self recursively
2019-07-06 14:22:15 +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
pyup.io bot 32bc0083d9 Scheduled monthly dependency update for July (#633)
* Update sphinx from 2.0.1 to 2.1.2

* Update typing-extensions from 3.7.2 to 3.7.4

* Update cython from 0.29.9 to 0.29.11

* Update isort from 4.3.20 to 4.3.21

* Update mypy from 0.701 to 0.711

* Update pytest from 4.6.0 to 5.0.0

* pytest and mypy fixes

* prevent deprication warnings
2019-07-06 09:39:39 +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 8aac71af0f Fix unparameterized generic type schema generation (#625)
* Fix #623

* Update history

* Add List test

* Augment test
2019-07-02 10:44:24 +01:00
Sebastián Ramírez 3cdbbaee95 Fix circular schema generation, remove None checking hack (#621)
* Fix circular schema generation, remove None checking hack

* Include test written by @wongpat to make it run in CI

* Update History

* Update nested_models in-place

Co-Authored-By: Patrick Wong <wongpat@users.noreply.github.com>

* Update nested_models in-place

Co-Authored-By: Patrick Wong <wongpat@users.noreply.github.com>

* Update nested_models in place everywhere for consistency
2019-06-28 10:49:26 +01:00
dmontagu ccdf8e12cd Fix #608 (repr on model with class) (#611)
* Fix #608

* add try-except

* Fix quotes
2019-06-26 14:03:33 +01:00
dmontagu 3f754c8cbd Fix #609 (default arguments for GenericModel) (#610)
* Fix #609

* Fix formatting

* update history

* add test for non-annotated fields

* Update tests/test_generics.py

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

* Update tests/test_generics.py

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

* Add another test
2019-06-25 10:58:23 +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
秋葉 6233554394 fix __post_init__ cause infinite recursion in inheritance (#606)
* fix __post_init__ cause infinite recursion in inheritance

* update changelog

* update code quote

* rename instance to self

* Update HISTORY.rst

Co-Authored-By: Samuel Colvin <samcolvin@gmail.com>
2019-06-21 10:46:21 +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
pfrederiks b77da1ec9e Add support for InitVar (#591)
* Add support for InitVar

* Annotate *initvars as Any

* Simplify tests

* Add line to HISTORY.rst

* Use dataclasses.fields which also ignores ClassVars

* tweak history
2019-06-14 16:56:08 +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
Sebastián Ramírez d73aa1bded Add support for JSON Schema with circular references in Python 3.7 (#572)
* Add support for circular references in generated JSON Schema

* Update JSON Schema for referenced models with overrides, using allOf

* Add tests for circular references in Python 3.7

* Update History

* Remove unnecessary check, raise coverage (remove partial)

* Trigger Travis and others

* Use str concat expression instead of double expression in schema

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

* Update pydantic/schema.py

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

* Partial implementation of PR review

* Simplify definition of known_models
2019-06-04 18:26:36 +01:00
Samuel Colvin 9ffa311f8f dataclasses to json (#575)
* dataclasses to json

* update history
2019-06-04 17:06:08 +01:00
Sebastiaan Van Hoecke 2a04aa76b0 added feature post_init_post_parse (#567)
* added feature post_init_post_parse

* fixed bug where post_init_post_parse was triggered without looking is post_init_original is set

* change double to single quotes

* __doc__ strings fixed back to double quote

* added better way of doing the post_init_post_parse also tests passes now

* removed unused file

* deleted unnecessary test

* update history.rst, changed previouis change 560 to breaking change because it broke the original flow

* update docs, added section post_init_post_parse under dataclasses

* added __post_init_post_parse__ as attribute of DataclassType

* Update HISTORY.rst

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

* Update HISTORY.rst

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

* Update pydantic/dataclasses.py

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

* update docs, added subsection initialize hooks under dataclasses

* my bad

* make tests work again

* removed checking if post_init_parse is none

* correct typo in history

* fixed typo in history.rst
2019-06-04 10:01:09 +01:00
pyup.io bot d10f473732 Scheduled monthly dependency update for June (#570)
* Update pygments from 2.3.1 to 2.4.2

* Update sphinxcontrib-websupport from 1.1.0 to 1.1.2

* Update email-validator from 1.0.3 to 1.0.4

* Update isort from 4.3.17 to 4.3.20

* Update pytest from 4.4.1 to 4.6.0

* Update pytest-cov from 2.6.1 to 2.7.1
2019-06-03 09:44:21 +01:00
Samuel Colvin d473f4abc9 cython (#548)
* user cython for fields.py, parse.py and validators.py, fix #547

* fix coverage

* no cython on windows

* speedup error_wrappers, more cython

* conditional validators

* more tweaks to validators.py

* add compiled check

* fix mypy and tweak

* benchmark with cython

* simplify anystr_strip_whitespace

* build binaries on travis

* fix travis manylinux builds

* correct test stages

* cibuildwheel to dist

* fix manylinux build

* don't upgrade pip on wheel build

* try a fix for cibuildwheel

* speedup deploy stage

* revert file rearrangement, cythonize main.py

* tweak main.py

* update docs and history

* fix deploy stage of travis

* Cythonize more files (#553)

* Cythonize more files

* Tests pass

* Fixed ordering

* Some code cleanup

* Every last file cythonized

* cython coverage

* upgrade cython and tweak build setup

* different build stages
2019-05-30 12:04:15 +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
Vítor Augusto da Silva Vasconcellos 79ed78fda0 Run dataclass' original __post_init__ before validation (#560)
* Run dataclass' original __post_init__ before validation

* Add unit test

* Update HISTORY.rst
2019-05-29 18:14:36 +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
Sebastián Ramírez cd8c7641bf Fix JSON Schema for list, tuple, and set, improving interoperability (#540)
* Fix JSON Schema for list, tuple, and set, improving interoperatibility

* Update History with PR number
2019-05-23 10:18:46 +01:00
Samuel Colvin 22f134475d Colors (#516)
* Color validator MVP

* Color Validator refactored

* Small optimizations applied

* Code coverage improved

* hex processing improved, json encoder and repr added

* Add documentation, update HISTORY (#504)

* Increase test coverage (#504)

* hex helpers refactored (#504)

* Fixes after code review (#509)

* Color Type section in docs reduced

* Check for valid but unnamed colors

* Minor fixes: typo in docs, default value for float comparison function

* rewrite Color

* fix color tests

* tweaks and improve docs

* tweaks and change Color.__str__

* add as_hsla and as_hsl

* support more rgb(a) formats

* add hsl parsing

* parsing hex with alpha channel

* fix hsl parsing

* simpler failure/fallback rules for color display

* storage as floats internally

* tweak docs

* fix type hints
2019-05-22 13:14:35 +01:00
euri10 c0298a8a76 Fix to schema generation for IPv{4,6}{Address,Interface,Network} (#532)
* Fix to schema generation for IPv{4,6}{Address,Interface,Network}, fix #498

* Added docs

* Added PR number

* Updated format to comply with http://json-schema.org/latest/json-schema-validation.html#rfc.section.7.3.4
Modified tests accordingly

* For real
2019-05-21 16:03:34 +01:00