Commit Graph

112 Commits

Author SHA1 Message Date
John Carter cd8b504568 Pass model_class to schema_extra staticmethod (#1125)
* Pass model_class to schema_extra staticmethod

Resolves #1122

* Add changelog

* Apply suggestions from code review

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

* Fix import after rebase

* Fix test bug

* Use TypeError instead of assert as per review

* Rename var so declaration fits one one line

* tiny tweaks

Co-authored-by: Samuel Colvin <samcolvin@gmail.com>
2020-01-06 12:01:03 +00:00
Samuel Colvin e169bd60e4 encourage use of version_info() in issues (#1138)
* encourage use of version_info() in issues

* improve grammar and add change

* switch test import
2020-01-02 19:34:33 +00:00
Samuel Colvin 31cac4783b improve pydantic import time (#1132)
* improve pydantic import time, fix #1127, fix #1039

* more tweaks

* tweak utils.py

* defering inspect
2020-01-02 14:35:03 +00:00
Samuel Colvin e9da909dd3 remove explicit re-exports from __init__.py (#1124) 2020-01-02 11:44:48 +00:00
Koudai Aono 2b47932f8e Fix EmailStr for Cython (#1126)
* Fix EmailStr for Cython

* add a change document.

* Fix NameEmail

* Update changes/1126-koxudaxi.md

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

* Update pydantic/networks.py

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

* Update changes/1126-koxudaxi.md

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

* Update pydantic/networks.py

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

Co-authored-by: Samuel Colvin <samcolvin@gmail.com>
2019-12-26 18:15:59 +00:00
Samuel Colvin e65d11240a uprev 2019-12-21 15:52:37 +00:00
Samuel Colvin 065ae2e4c4 fix modify schema (#1103)
* modify schema, fix #1102

* remove DSN from schema table

* fix tests

* add outer_type_ to ModelField, fix coverage

* simplify ModelField._type_display

* remove debugs

* revert change to _type_display

* test fix
2019-12-21 15:46:11 +00:00
Samuel Colvin e1ae058afb Consistent checks for sequence like objects (#1111) 2019-12-20 15:08:45 +00:00
Marcus McCurdy d63e9b64ce Fix for Optional Json fields (#1080)
* Fixes #1073

* remove test

* fix tests

Co-authored-by: Samuel Colvin <samcolvin@gmail.com>
2019-12-20 14:04:22 +00:00
François Voron e478278474 Documentation: rename benchmark django-restful-framework -> django-rest-framework (#1119)
* Rename django-rest-framework benchmark

* Add change file for #1119

* Rename django-rest-framework in existing benchmarks results
2019-12-20 11:31:16 +00:00
Anthony 1a273f2e64 docs: Fix explanation of case sensitivity for Settings (#1110)
* docs: Fix explanation of case sensitivity for `Settings`

* Add changes

* Update docs/usage/settings.md

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

* Update docs/usage/settings.md

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

* Update docs/usage/settings.md

Co-Authored-By: Samuel Colvin <samcolvin@gmail.com>
2019-12-18 14:16:38 +00:00
Aviram Hassan 5510a13f6c Added optional for root_validator to be skipped if values validation fails (#1050)
* Added optional for root_validator to be skipped if values validation fails

* cleaner usage of skip_on_failure

* skip_on_failure: documentation update
2019-12-16 11:15:06 +00:00
Samuel Colvin bd72e80e94 Prevent type attributes being added to schema unintentionally (#1065)
* Prevent type attributes being added to schema unintentionally, fix #1064

* simpler boolean check

* change to __modify_schema__

* better docs

* Update docs/usage/schema.md

Co-Authored-By: dmontagu <35119617+dmontagu@users.noreply.github.com>
2019-12-11 12:01:41 +00:00
Samuel Colvin de6bd1b469 Settings config inheritance fix #1091 (#1093) 2019-12-11 11:58:03 +00:00
Scott P 3804998649 Trick Cython into allowing str subclassing (#1061)
* Trick Cython into allowing str subclassing

* Added a changes file

* Removed 2nd paragraph from changes file so it passes tests

* Augmented with tests for StrictInt/Float

* Removed commented out StrictBool subclass testing
2019-12-10 11:07:56 +00:00
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