Commit Graph

97 Commits

Author SHA1 Message Date
Søren Bjerregaard Vrist 33fee6d9be Let SecretStr/SecretBytes be value equals to them selves (#1079)
fix #1078
2019-12-09 17:23:34 +00:00
Selim Belhaouane bdc3973d90 Allow schema_extra to be a callable (#1054)
* fixes for Windows development

* Allow Config.schema_extra to be a callable
2019-12-09 11:01:17 +00:00
Greg Lutostanski 34a64efc04 Fix schema for fields with nested None as default (#1088)
fix #1087

As None is typically used for the default value, it is not usually
encoded on its own into schemas. There was an issue, where using None
not as the top-level value, but rather inside other objects (e.g.
[None]) will throw a Traceback.
2019-12-09 10:05:55 +00:00
Sebastián Ramírez ea709cc66f Add FastAPI tests to Pydantic's CI tests (#1075)
fix #1041

* Add test-fastapi.sh script, after failing to create reusable variables in Make

* Add test-fastapi Make target

* Add fastapi dir for tests to gitignore

* Add fastapi tests to Travis

* Update test-fastapi to run the minimum (pytest)

* Move make test-fastapi to normal run, no "Without Deps"

* Install Pydantic without Cython for FastAPI tests

* Put FastAPI tests in its own Travis job

* Add PR changes description

* Remove coverage for FastAPI, it's not relevant for Pydantic

* Implement code review changes, refactor Makefile use and fastapi tests

* Add a bug intentionally, to test that FastAPI tests are using the current source

and make sure it actually breaks CI.

* Fix intentional bug. Confirmed it breaks Travis for FastAPI.
2019-12-05 11:35:56 +00:00
Samuel Colvin 13f4b8989e more strict mypy checks (#1077)
* more strict mypy checks

* add change
2019-12-04 15:15:13 +00:00
Samuel Colvin 15b981d05f change cython nthreads default to zero (#1074)
* change cython nthreads default to zero

* add change
2019-12-04 13:30:30 +00:00
Kieran Darcy 9982eb43dd Change BaseModel.parse_file to use Config.json_loads (#1069)
fix #1067

* Making json_loads available to parse_file

* Change BaseModel.parse_file to use Config.json_loads

* Update changes/1067-kierandarcy.md

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

* Fixed some style issues and added missing test for parse_file_as
2019-12-03 15:05:27 +00:00
dmontagu d538df5fbb Update for compatibility with mypy 0.750 (#1058)
* Update for compatibility with mypy 0.750

* Remove coverage checks for 0.740 compatibility
2019-12-02 13:09:37 +00:00
Aviram Hassan 1b9f08bead Dataclass is now compatible with schema methods (#1045) 2019-12-02 12:44:21 +00:00
Samuel Colvin b521f6b24a prepare v1.2 (#1042)
* making field-reuse idempotent (#1016)

* making field-reuse idempotent

* fix for 3.6

* correct change details

* uprev

* generate HISTORY.md
2019-11-28 17:46:43 +00:00
Sebastián Ramírez d9bbb05a16 Implement Optional required (#1031)
* Implement Optional required, when creating a ModelField(required=True), make it persist

* Add test for nullable required

* Improve formatting of Undefined custom object

* Refactor field infer/creation with Undefined to make it idempotent

Needed for when _type_analysis is re-run in Generics

* Add PR changes

* Increment/update tests with code review

* Update/refactor Undefined implementation with code review

* Fix BoolUndefined as string type for mypy, not runtime

* Add docs about required Optional

* Add explicit tests for Any

* Apply code review requested changes

* move tests out of test_validators.py
2019-11-28 16:48:33 +00:00
dmontagu c71326d4a6 Add better support for validator reuse (#941)
* Add better support for validator reuse

* Clean up classmethod unpacking

* Add changes

* Fix coverage check

* Make 3.8 compatible

* Update changes/940-dmontagu.md

Co-Authored-By: Samuel Colvin <s@muelcolvin.com>

* Make allow_reuse discoverable by adding to error message

* switch _check_validator_name to _prepare_validator
2019-11-25 15:15:05 +00:00
dmontagu 6564bbb4ce Add parse_as_type function (#934)
* Add parse_as_type function

* Add changes

* Incorporate feedback

* Add naming tests

* Fix double quotes

* Fix docs example

* Reorder parameters; add dataclass and mapping tests

* Rename parse_as_type to parse_obj, and add parse_file

* Incorporate feedback

* Incorporate feedback

* use custom root types
2019-11-25 12:55:15 +00:00
dmontagu 62bc930f57 Add support for mapping types as custom root (#958)
* Add support for mapping types as custom root

* Incorporate feedback

* Add changes

* Incorporate feedback

* Add docs and tests

* Fix linting issue

* Incorporate more feedback

* Add more specific match
2019-11-25 12:19:41 +00:00
dmontagu 643266944c Support typing.Literal in python 3.8 (#1027)
* Support typing.Literal in python 3.8

* Improve import pattern for Literal

* Update references to  in docs

* Try to get build to pass
2019-11-25 11:32:01 +00:00
Colin Sullivan 043186cfcd add testimonials section to docs with reference to python bytes podcast episode (#1025)
* add testimonials section with reference to python bytes podcast episode

* added description to changes directory
2019-11-22 16:21:02 +00:00
Samuel Colvin 4e23d4a61f __str__ and __repr__ inheritance for models, fix #1022 (#1023) 2019-11-22 15:29:56 +00:00
Niko Strijbol fd32516e0f Add exclude_none option (#1003)
* add `exclude_none` option (#587)

* run formatter

* Apply @samuelcolvin's suggestions
2019-11-18 13:18:51 +00:00
Daniel Smith c2e0082800 ByteSize conversion (#996)
* Bytesize implement to conversion

* Changelog

* Lint: changes to single quotes

* Update tests/test_types.py

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

* Update tests/test_types.py

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

* Update tests/test_types.py

Co-Authored-By: Samuel Colvin <samcolvin@gmail.com>
2019-11-14 16:22:51 +00:00
Koudai Aono 33b3dc1825 mypy plugin support for dataclasses (#966)
* mypy plugin support for dataclassesv

* fix styles and types

* - change type-hint for `Config`
- change name of an expected file
- update documents

* fix broken a reference of a document.

* - update unittest
- update documents

* fix a document link

* Update docs/mypy_plugin.md

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

* Update docs/mypy_plugin.md

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

* Update docs/mypy_plugin.md

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

* remove extra whitespaces on mypy test results

* fix output file name of mypy test

* Update docs/usage/dataclasses.md

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

* use TypeVar for DataclassType
2019-11-14 11:26:46 +00:00
Samuel Colvin 0e8f88611f build binaries for python 3.8 (#994)
* build binaries for python 3.8

* change and test with cibuildwheel

* skip codecov on pypi build

* speed up PR ci builds

* better conditional builds

* fix conditional builds

* finish conditional stages
2019-11-14 10:50:34 +00:00
Samuel Colvin e46491d951 move change 2019-11-13 19:20:33 +00:00
Samuel Colvin f4cc204138 fix mypy complaint on @root_validator(pre=True) (#985)
* fix mypy complaint on @root_validator(pre=True)

* fix internal mypy

* use overload on root_validator
2019-11-09 14:45:29 +00:00
Daniel Smith b92e74d0a6 Bytesize (#977)
* ByteSize object

* Human readable format

* Lint, tests, and docs

* Update pydantic/errors.py

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

* Update pydantic/types.py

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

* Update pydantic/types.py

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

* Allows human readable decimal descriptor

* Review comments

* Less verbose testing

* ByteSize docs

* Reworks valid units

* Missing type

* tweak tests
2019-11-09 12:39:02 +00:00
Alexander Hirner c188b3fba8 Feature/dataclass schema defaults (#980)
* default dataclass field from default_factory

* silence mypy regarding issue 708

* test dataclass factory function default

* test default factory ending up in schema

* add changes md

* add docs for dataclass default factory and basemodel access

* fully print default factory schema
2019-11-09 12:29:15 +00:00
Sebastian Mika b87ca4ee05 benchmark for cattrs (#513)
* benchmark for attr

* update HISTORY.rst

* * added benchmark using cattr
* add env "ATTRS=1" to benchmark runner to only compare again the two
  and save results in separate csv
* added section to docs/index

* nits

* re-run benchmark with cython pydantic; merge results back to main benchmarks results table

* pin pydantic to top of benchmark report

* remove attrs, fix cattrs

* update benchmarks output

* add change
2019-11-08 17:04:41 +00:00
Samuel Colvin 8a261c1dfa uprev and generate history 2019-11-07 15:20:27 +00:00
Samuel Colvin 1d3f7824ec Fix broken Any and TypeVar behaviour (#962)
* tests for broken Dict behaviour

* fix Any, support TypeVar

* change type of field.type_

* add docs and example for TypeVar
2019-11-07 12:31:26 +00:00
Samuel Colvin afa0bd4104 set FieldInfo on subfields (#969)
* set FieldInfo on subfields

* fix coverage
2019-11-07 10:34:49 +00:00
dmontagu 0c18619769 Mypy plugin (#722)
* Add mypy plugin

* Make all arguments optional for BaseSettings

* Get test coverage up

* Add changes

* Add type-checking for BaseModel.construct, and checking for from_orm

* Fix formatting and linting

* Fix the build

* Heavy refactor of plugin and mypy tests

* Make linting pass

* Handle dynamic aliases

* Better organize plugin code

* Add docs

* Add support for error codes

* Fix minor docs typo

* Rename config settings, add docstrings, and incorporate other feedback

* Incorporate feedback

* Update docs, remove dataclasses for cython

* fix mypy example
2019-10-31 13:19:01 +01:00
dmontagu cb2a302520 Fix generic typehint for pycharm (#936)
* Fix generic typehint for pycharm

* Add changes
2019-10-29 15:15:28 +01:00
Samuel Colvin b8bbfec670 release notes for v1 (#918)
* release notes for v1

* uprev and tweaks

* Apply suggestions from code review

Co-Authored-By: dmontagu <35119617+dmontagu@users.noreply.github.com>

* tweak notes, add back link to old docs

* build changelog
2019-10-23 11:48:14 +01:00
retnikt dccc4014dc Clarify documentation and error message about keep_untouched (#926)
* Clarify keep_untouched documentation (#924)

* Clarify error message for custom types (#924)

* Fix tests for changed error message (#924)

* fix formatting

* remove erroneous error message and add change
2019-10-23 11:14:51 +01:00
Samuel Colvin bab6970f12 allow abstract sets in include and exclude arguments (#921)
* allow abstract sets in include and exclude arguments

* add change

* correct type hints
2019-10-23 11:03:29 +01:00
Samuel Colvin 677677e536 modify behaviour of the construct method (#898)
* modify behaviour of the construct method

* change construct signature

* Add example for construct function (#907)

* add example for construct

* edit exporting_models

* typo

* add changes file

* code review changes

* fix bad copy paste

* extend example in docs

* use __field_defaults__ in construct
2019-10-23 10:49:05 +01:00
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