Commit Graph

394 Commits

Author SHA1 Message Date
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
Jan Vlčinský 7000a27d56 doc: self-referencing got note about rq for python 3.7+ (#618)
* doc: self-referencing got note about rq for python 3.7+

* Update HISTORY.rst

* Use issue # in history record
2019-06-24 14:37:54 +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
Samuel Colvin dd44fda8a6 uprev 2019-06-19 11:28:14 +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
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
Samuel Colvin f5b054b9fc fix deploy 2019-06-11 07:59:01 +01:00
Samuel Colvin 795efe5c1c uprev 2019-06-06 17:33:15 +01:00
Samuel Colvin 8ad9fa45df tweak travis (#581)
* tweak travis

* fix codecov env vars

* try again with env vars
2019-06-06 16:59:21 +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
dmontagu 6d5c48e3fd Fix Cython compiled check in ipython (#573)
* Update main.py

Addresses the issue raised in #548 related to running non-compiled in IPython

* except AttributeError

* update HISTORY.rst
2019-06-04 22:07:32 +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 d69ca21ce4 add 'none-any.whl' to pypi upload (#564)
* add 'none-any.whl' to pypi upload

* reset 'if'
2019-05-30 16:15:55 +01:00
Samuel Colvin 26cbe4868c uprev 2019-05-30 15:29:20 +01:00
Samuel Colvin b248a0984f update benchmarks (#563)
* update benchmarks

* optimize
2019-05-30 12:43:44 +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 4263258207 try to stop annoying warnings in azure pipeline (#549) 2019-05-25 19:10:52 +01:00
Samuel Colvin 9eb132ce99 azure pipeline failOnStderr: false 2019-05-25 18:59:54 +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 d2f6073721 uprev. 2019-05-22 14:06:22 +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
David Sommerich cb2abb10b6 Fix __fields_set__ not using alias field names (#517) (#518)
* Fix __fields_set__ not using alias field names (#517)

fix #517

* Update HISTORY.rst

* Fix single quotes

* Don't need to check allow_population_by_alias

* Calculate fields_set in validate_model instead

* Fix formatting

* Add breaking change to history

* Minor fixed to validate_mode

* Minor fixes to tests

* Add comments for names_used and fields_set in validate_model
2019-05-18 12:11:33 +01:00
dmontagu 9b98d14ff1 Change return type hint for create_model (#526)
* Change return type hint for create_model, fix #525

* remove unnecessary ignore

* Update HISTORY.rst
2019-05-16 10:49:12 +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
Vitaly R. Samigullin f8b946b8c2 Fix to schema generation for IPvAny{Address,Interface,Network} (#498) (#510)
fix #498
2019-05-08 10:39:43 +01:00
Samuel Colvin 6d80a1a65e uprev 2019-05-05 14:09:53 +01:00
pyup.io bot 983f886f77 Scheduled monthly dependency update for May (#499)
* Update sphinx from 2.0.0 to 2.0.1

* Update isort from 4.3.16 to 4.3.17

* Update mypy from 0.670 to 0.701

* Update pytest from 4.4.0 to 4.4.1

* Update pytest-mock from 1.10.3 to 1.10.4

* fix typing
2019-05-05 14:08:18 +01:00
Sean Marshallsay 8149e09332 Implement const keyword in Schema. (#469)
* feat: implement const keyword in Schema

Fix #434.

* make fields marked `const` optional

* move `const` out of the `Field`

* check that `schema` is not `None` instead of using `getattr`

* tweak constant error
2019-05-05 14:00:36 +01:00
Samuel Colvin bff8a1789d single quotes in tests 2019-04-25 11:54:05 +01:00
jakeb a3d9ad16e7 Fix dict with extra keys (#490)
* Fix dict with extra keys (#489), fix #488

* Fix PR number

* Fix Config of MyModel not to inherit BaseConfig
2019-04-25 11:50:58 +01:00
theenglishway e5b8ec7750 improve doc on self-referencing models and annotations (#487) 2019-04-24 10:06:03 +01:00
Samuel Colvin 94c27b6334 uprev. 2019-04-23 15:11:18 +01:00
Mike Goodspeed 0cfce77bb3 fix json for Path, FilePath, and DirectoryPath objects (#485)
* fix json for Path, FilePath, and DirectoryPath objects, fix #473

* convert to single spaces

* assert result to a string

* Update test_json.py

* encode entire Path hierarchy the same way
2019-04-23 15:09:09 +01:00
Andrew Sultana edafaf9b86 Fix ISO 8601 timedelta spec given in docs (#482) 2019-04-20 10:27:10 +01:00
NoAnyLove 2ca81ed33f Fix nested dataclass schema (#475)
* Add test case for nested dataclass schema, fix #474

* Fix nested dataclass schema

* Fix mypy typing

* Update HISTORY.rst

* Code review updates
2019-04-18 10:10:36 +01:00
Samuel Colvin 65d717a7b7 fix parse_obj for dict-like object (#476)
* fix parse_obj for dict-like object, fix #472

* correct internal errors with parse_obj
2019-04-17 10:46:23 +01:00
primal100 50fd2c5b48 Validators for dataclasses (#454)
* Added validators for dataclass, fix #415

* Added dataclass validators

* Added dataclass validators

* Updated docs for added validating to dataclass

* Updated docs for added validating to dataclass

* Fixed line endings

* Set __validators__ type to Mapping instead of Dict

* Update History

* Use __mro__ instead of __bases__ for gather_validators

* Fix PR number

* Fix issue.rst header underline

* Fix HISTORY.rst merge conflict

* Fix utils.py merge conflict

* fix utils.py

* Rebase and other fixes

* Fix rebase and other issues

* Change history

* Remove unnecessary lines in main.py

* Rebase

* Update history

* Rename ModelType to ModelOrDc

* Added inheritance replace test

* More consiste dataclass validator tests

* fix history.

* Remove Optional ModelOrDc Type

* Fix ModelOrDc
2019-04-11 23:13:57 +01:00
Samuel Colvin 3fa31754fe add #465 to history 2019-04-11 20:41:55 +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