Commit Graph

216 Commits

Author SHA1 Message Date
Tyler Wozniak 3e4c1b5714 Adding deque to valid field types (#1935)
* Adding deque to valid field types

* Added missing type example

* Fix bad copy-paste

Co-authored-by: PrettyWood <em.jolibois@gmail.com>

* correct enum validator name

* correct enum validator name, take2

Co-authored-by: PrettyWood <em.jolibois@gmail.com>
Co-authored-by: Samuel Colvin <s@muelcolvin.com>
2020-10-25 17:52:34 +00:00
Noel Evans 8b2f299fc5 Fix representation of literal enums (#1747) (#1838)
* Fix representation of literal enums (#1747)

Use existing is_literal_type

Skip when typing_extensions is not present

Improvements proposed by PrettyWood reviewing PR

* Trim unnecessary logic

* Clarify behaviour

* extend test slightly

Co-authored-by: Samuel Colvin <s@muelcolvin.com>
2020-10-25 16:48:03 +00:00
Gabriel d14731f16c schema ref_template (#1480)
* ignore Pipfile, .lock files

* add ref_template option

use a string.Template instead of a ref_prefix to allow for more varied`$ref`s to be created.
Template string is expected to have $model_name `identifier `

* formatting / linting

* add changes

* typo

* use string.format instead of string.Template

* remove ref_prefix default

if no `ref_prefix` provided, use the `template_default`

* use ref_template in field_singleton_schema

* fix test_schema_with_ref_template

* add parameters for `test_schema_with_refs`

test name change 
test for key error

* provide ref_template default argument

* fix linting

* fix mypy and coverage

* docs and correct model_schema usage

* fastAPI tests actualy caught an error

* linting

Co-authored-by: Samuel Colvin <s@muelcolvin.com>
2020-10-25 16:24:37 +00:00
Noel Evans 5da8b9cded Parse time with tz (#1814)
* Parse timezone information in time str

* Add description of change fixing issue 1744

* Guard against TZ over 24 hours

* Parse timezone information in time str

* Datetime and time TZ parsed in separate fn

* Sharpen annotation, many return statements

* Fix mypy errors raised on datetime_parse

* fix type hints

* update docs and correct types

Co-authored-by: Samuel Colvin <s@muelcolvin.com>
2020-10-25 16:08:38 +00:00
PrettyWood 4bc4230df6 feat: support default_factory with BaseModel.construct (#1755)
* feat: support `default_factory` with `BaseModel.construct`

closes #1732

* refactor: remove __field_defaults__

* docs: update change with `__field_defaults__` deletion
2020-10-25 15:41:57 +00:00
Sergey Teplyakov 52aa5c456f Add init for forward ref stub (#1739)
* Add __init__ for ForwardRef stub

* Add changes file

* Update changes/1738-sirtelemak.md

Co-authored-by: Samuel Colvin <samcolvin@gmail.com>

* Add mypy check for ForwardRef

* Add Black line after if statement

Co-authored-by: Samuel Colvin <samcolvin@gmail.com>
Co-authored-by: Sergey Teplyakov <s.teplyakov@fitingo.com>
Co-authored-by: Samuel Colvin <s@muelcolvin.com>
2020-10-25 15:36:38 +00:00
Samuel Colvin a25aba26b5 linting as a separate CI step (#2030)
* linting as a separate ci step

* CI and docs improvements

* fix docs preview

* fix docs, benchmarks fastapi tests

* fix formatting and docs build

* tweak publishing docs

* fix for new download-artifact action

* skip check tag to check docs build

* prepare for merge
2020-10-25 15:03:33 +00:00
Arseny Boykov 6b53cabe03 Add pickle support to dynamically created models and generics (#1686)
* Add pickle support to dynamically created models

* Add created model module check

* Use globals() to retrieve model

* Use single quotes

* use mocker instead of mock

Co-authored-by: PrettyWood <em.jolibois@gmail.com>

* remove unused import

* add test for dynamic forward ref

* move generic test to test_generics.py

* fix test_generic_model_pickle test, add additional check for <locals> in create_model

* fix code style

* resolve issues with global/local models

* make ensure_picklable return given model

* remove ensure_picklable, use test_is_call_from_module only in generics

* reformat code after updating black==20.8b1

* move get_caller_module_name and is_call_from_module to generics

* apply suggestions from @samuelcolvin

* add tests for get_caller_module and is_call_from_module called from module

* fix linting

* fix path to modules in test_module fixture, capture stderr and stdout

* fix broken test module

* fix subprocess call for windows

* enhance create_module fixture, add run_as_module fixture

this will allow run modules in subprocess and define module code in functions-containers

* add test for redefined concrete model without cache

* add changes file

* remove unused variable

* rewrite tests with pytest.raises

* fix linting

* rewrite test_create_model_pickle and test_forward_ref_with_create_model with module definition in function

* Update create_model docstring

Co-authored-by: PrettyWood <em.jolibois@gmail.com>
Co-authored-by: Samuel Colvin <s@muelcolvin.com>
2020-10-18 20:55:44 +01:00
PrettyWood ab671a3670 feat(field): add Enum and IntEnum as valid types for fields (#1737)
* feat(field): add Enum type support

closes #1735

* test: add extra cases and rename to be more explicit

* refactor: rename enum_validator

* feat: add Enum and IntEnum types support

* docs: add new types

* chore: update change message
2020-10-18 20:53:29 +01:00
PrettyWood 794d0bccf9 feat: add basic support for python 3.9 (#1844)
* feat: use partially get_origin and get_args from typing

Rework of d86a184072655d93652d6ea941421005f34de962 by @hmvp
We cannot directly use `typing.get_origin` and `typing.get_args` for
our custom types for which args and origin are wrong by default.
But at least we now have a unified behaviour, which can be improved
in the near future

* feat: add fallback in `get_args` for generics in python 3.9

* feat: add new `_evaluate` for python 3.9

In python 3.9, `typing._evaluate` has a new required
positional argument `recursive_guard`

* chore: add pragma no cover for python 3.9 fallbacks

* chore: add change file

* chore: add comments

* feat(ci): add python 3.9 support

* fix: mypy assumption is wrong
2020-10-18 20:36:18 +01:00
PrettyWood 3aacec4e17 feat(schema): support custom title, description and default for enums (#1749)
* refactor(schema): put schema data from fieldinfo in dedicated function

* feat(schema): support custom title, description and default for enums

closes #1748

* refactor: replace $ref by allOf + $ref to be supported by doc generation tools

* fix: do not set title by default for enums

* refactor: make code more explicit

* fix: run linter
2020-10-18 20:23:06 +01:00
Louis Sautier e8326f899e Include tests in source distributions (#1976) 2020-10-09 14:32:27 +01:00
Hmvp c6a24f28c5 Fix const validator not running when class validators are present (#1957) 2020-10-09 13:26:11 +01:00
Davis Kirkendall 30ee8e2203 Force fields.Undefined to be a singleton objectIn various places of the code, we compare directly to fields.Undefinedsince we assume it to be constant.When new models get created however, the object is deepcopied andis no longer identical with the original object.We therefore add __copy__ and __deepcopy__ methods to ensurethat the copied objects are actually the same original object. (#1981) 2020-10-09 13:25:24 +01:00
Brian Maissy a89c97a3e3 add a __call__ stub to PyObject for mypy (#1849)
Co-authored-by: Brian Maissy <brian@medigate.io>
2020-10-09 12:11:23 +01:00
Geon Kim - KimMachineGun be8ef63a33 docs: Fix incorrect description of copy method (#1821)
* docs: Fix typo

* docs: Fix incorrect description of copy method

* changes: Add changes description file

* docs: Add space before parentheses

Co-authored-by: PrettyWood <em.jolibois@gmail.com>

Co-authored-by: PrettyWood <em.jolibois@gmail.com>
2020-10-09 11:28:04 +01:00
PrettyWood 75859a9d58 feat(tools): add parse_raw_as util (#1813)
closes #1812
2020-10-09 10:35:07 +01:00
PrettyWood 76fdbe92be feat(dotenv): support home directory relative paths (e.g. ~/.env) (#1804)
closes #1803

Co-authored-by: Samuel Colvin <s@muelcolvin.com>
2020-10-09 10:23:28 +01:00
Matthew Davis 094da94da9 clarify argument type to parse_file (#1795)
Co-authored-by: Matthew Davis <Matthew.Davis.2@team.telstra.com>
2020-10-08 21:10:09 +01:00
Selim Belhaouane b99c37e3d0 Fix #1770 (#1771) 2020-10-08 21:07:22 +01:00
PrettyWood 55e78cc106 fix(schema): add basic support of Pattern type in schema generation (#1768)
closes #1767
2020-10-08 20:42:14 +01:00
PrettyWood a2fc01a59b fix: forward ref with nested models and optional fields (#1752)
* fix: forward ref with nested models and optional fields

PR #1712 introduced a regression for forward refs in `ModelField.prepare`
as it would not return early for forward refs anymore.
Optional fields would hence have `required` set to `True`.

closes #1736

* test: skip python 3.6 as __future__.annotations is not defined
2020-10-08 20:26:30 +01:00
Samuel Colvin 9c4860ce96 Valdiate arguments config (#1663)
* add `configs` to validate_arguments

* simplify `validate_arguments` and add annotation for parameter `configs`

* change double quotes to single quotes

* reformat code

* fix mypy error

* fix mypy 'maximum semantic analysis' error

* rename 'configs' > 'config_params'

* change name and usage, start tests

* prevent setting fields on custom config

* add docs and fix mypy

* tweak docs

* add change

Co-authored-by: quantpy <quantpy@qq.com>
2020-09-06 23:17:52 +01:00
Yury Paykov 0a465b6216 Fix #1561 - apply Config env names for fields defined in the parent c… (#1585)
* Fix #1561 - apply Config env names for fields defined in the parent class

* Changes

* Fix lint

* Fix typing

* More tests
2020-09-06 16:51:38 +01:00
Samuel Colvin d2b050176e uprev 2020-07-15 20:24:20 +01:00
PrettyWood e2fcab52b9 fix: validate and parse nested models properly with default_factory (#1712)
* fix: validate nested models with `default_factory`

PR #1504 introduced a regression by bypassing `populate_validators()`,
which would skip the validation of children in nested models
with `default_factory`

closes #1710

* test: add example of nested models parsing with `default_factory`

closes #1717

* add testcase from #1722

* bodge for benchmarks

Co-authored-by: Samuel Colvin <s@muelcolvin.com>
2020-07-15 20:23:18 +01:00
Samuel Colvin 2440ab931e uprev and changes 2020-07-11 11:45:15 +01:00
Spiros Dontas 1f4ecd0785 Fix nested all include exclude (#1588)
* Fix nested all include exclude

* Ensure original exclude value is not modified

This commit also fixes some weird cases in the recursive
`update_normalized_all` call and Ellipsis values.

* Add docstring, parametrize tests
2020-07-11 11:28:53 +01:00
Samuel Colvin a913c37560 Fix master (#1682)
* Fix master

* Fix master 2 (#1694)

* test: add regression test with wrong type default

* fix: remove always on conlist and conset

* fix: use utf8 as default encoding on all OS

* conset invalid defualt test

* add change

Co-authored-by: PrettyWood <em.jolibois@gmail.com>
2020-07-09 14:26:27 +01:00
flapili dac6764575 Url port check (#1678)
* add url port check

* add change

* Update pydantic/networks.py

fix typo

Co-authored-by: PrettyWood <em.jolibois@gmail.com>

* Update 1654-flapili.md

* Update 1654-flapili.md

Co-authored-by: PrettyWood <em.jolibois@gmail.com>
Co-authored-by: Samuel Colvin <samcolvin@gmail.com>
2020-07-03 20:56:36 +01:00
Patrick Wang dca98559d5 Add conset (#1627)
* Add conset

* Add changes doc

* Fix too-long lines

* bump

* Update conset change doc formatting

Co-authored-by: Samuel Colvin <samcolvin@gmail.com>

* Robustify test_conset

* Move conlist and conset tests to test_types

Co-authored-by: Samuel Colvin <s@muelcolvin.com>
Co-authored-by: Samuel Colvin <samcolvin@gmail.com>
2020-07-03 20:51:23 +01:00
beezee e3c5e1d3cd aggregate root validation errors (#1586)
* aggregate root validation errors

* add changelog

* update language in docs around root validators and prior failure

* factor out unique_list
2020-07-03 20:47:04 +01:00
John Carter ff20477521 Apply __modify_schema__ on enum schema rather than fields that use it (#1581)
* Apply __modify_schema__ on enum schema rather than fields that use it

Resolves #1576

* tweak test

* correct linting :-(

Co-authored-by: Samuel Colvin <s@muelcolvin.com>
2020-06-29 13:22:27 +01:00
ll H 8aebba2c35 check ModelField().validate_always when inheriting (#1545)
fix #1155

* fix issure #1155

* add changes.1545-dcHHH.md

* improve change description

Co-authored-by: dchhh <hudacong@geetest.com>
Co-authored-by: Samuel Colvin <samcolvin@gmail.com>
2020-06-29 11:04:44 +01:00
PrettyWood e5fff9ccd0 fix: make pydantic errors (un)pickable (#1630)
* fix: make pydantic errors (un)pickable

closes #1616

* add typing

* refactor: rename kwargs into ctx
2020-06-27 19:31:23 +01:00
Yuri Khan 908f6edb72 Document default regex anchoring semantics (#1631) (#1648) 2020-06-27 19:16:32 +01:00
Ram Rachum ecb54c5d36 Use chain.from_iterable in class_validators.py (#1642)
* Use chain.from_iterable in class_validators.py

* fix change

Co-authored-by: Samuel Colvin <s@muelcolvin.com>
2020-06-27 18:43:28 +01:00
Patrick Wang 5a2d78765a squash internal __root__ models in .dict() (#1607)
fix #1414

* flatten internal __root__ models

* add 1414 changes doc
2020-06-27 14:55:17 +01:00
Mlbiche 113921c6c5 Update datetime parser to support negative timestamps (#1605)
- Negative timestamps corresponds to dates before 1970/1/1
2020-06-27 14:52:20 +01:00
Samuel Eklund 7bd635c21c Subclass validator each item docs (#1592)
* add description of subclass each_item scenario

* add example of subclass validator with each_item

* each_item causes validator to not run when parent class has List field #1566
2020-06-27 14:51:18 +01:00
PrettyWood 7ac9faf031 (fix) use right type check when modifying schema (#1562)
fix #1552
2020-06-27 14:12:36 +01:00
PrettyWood c59db275dc fix(field): remove some side effects of default_factory (#1504)
* Avoid some side effects of default factory

- by calling it only once if possible (fix #1491)
- by not setting the default value in the schema (fix #1520)

* refactor: ensure type is set when using default_factory
2020-06-27 14:02:29 +01:00
Samuel Colvin d122b1dbdc remove RedisDsn.user_required = True (#1658)
* remove RedisDsn.user_required = True

* update docs
2020-06-26 12:02:57 +01:00
dependabot-preview[bot] 70d531ff4c Bump mypy from 0.770 to 0.780 (#1598)
* Bump mypy from 0.770 to 0.780

Bumps [mypy](https://github.com/python/mypy) from 0.770 to 0.780.
- [Release notes](https://github.com/python/mypy/releases)
- [Commits](https://github.com/python/mypy/compare/v0.770...v0.780)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>

* fix mypy errors and remove AnyType

* fix python 3.6 inconsistencies

* linting

* tweak typing

* fix typing for 3.6

* bump

Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
Co-authored-by: Samuel Colvin <s@muelcolvin.com>
2020-06-25 19:24:37 +01:00
PrettyWood 0cee311be5 feat(settings): allow custom encoding for dotenv files (#1620)
closes #1615
2020-06-11 11:04:08 +01:00
PrettyWood 329b1d3e7b fix: type hints on BaseConfig (#1618)
closes #1614
2020-06-09 10:32:07 +01:00
wangpeibao 5e82689c79 Change schema frozenset (#1560)
* add frozenset to field_class_to_schema

* add change.md

* add my test

* format my test

* remove print()

* just test

* return to original code

Co-authored-by: wangpeibao <wangpeibao@troila.com>
Co-authored-by: Samuel Colvin <s@muelcolvin.com>
2020-06-02 11:03:12 +01:00
Koudai Aono 6e29848608 Add datamodel-code-generator link in pydantic document site (#1532)
* Add datamodel-code-generator link in pydantic document site.

* tweak menu

* fix blank lines

Co-authored-by: Samuel Colvin <samcolvin@gmail.com>
Co-authored-by: Samuel Colvin <s@muelcolvin.com>
2020-05-31 15:23:20 +01:00
Shawn Wall 4f9e77d213 1541 UUID bytes support for 16 byte strings / BINARY(16) (#1542)
* [1541] add fallback to UUID instantiation through bytes

* [1541] added changes md file

* Update UUID docs for bytes/bytearray

Co-authored-by: Shawn Wall <shawn@civicscience.com>
2020-05-31 15:05:53 +01:00
John Carter 827388b4fe Add a test assertion that default_factory can return a singleton (#1523) 2020-05-31 14:51:50 +01:00