Commit Graph

347 Commits

Author SHA1 Message Date
Eric Jolibois 1c3ef841e6 feat: add validator for None, NoneType or Literal[None] (#2149)
* feat: add validator for NoneType

closes #2095

* feat: support NoneType directly as type

* chore: add change file

* chore: fix typo

* fix: handle Literal[None] for python3.6/3.7 without typing_extensions

* chore: move NotNoneError and export it

* chore: use constant NONE_TYPES to simplify a bit

* chore: use check on Literal instead of typing_extensions

These tests would not run on python 3.8+ without typing_extensions
even though Literal is defined

* test: use fresh Literal[None] in test case

* feat: handle `None` type in schema

* docs: add NoneType documentation

* refactor: switch NONE_TYPES from tuple to set
2021-01-01 14:01:25 +00:00
Eric Jolibois 8bad7bc911 feat: add validate method on function to validate input without calling it (#2128)
* feat: add `validate` method on function to validate input without calling it

* docs: add documentation

* chore: add change file
2020-12-31 17:45:51 +00:00
Mykola Solodukha aacf592040 Add rediss (Redis over SSL) protocol to RedisDsn (#1911)
* Add `rediss` (Redis over SSL) protocol to `RedisDsn`

* Update docs

* Update changes history

* Fix typo in `changes/1911-TrDex.md`

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

* Bump black from 19.10b0 to 20.8b1 (#1909)

* Bump black from 19.10b0 to 20.8b1

Bumps [black](https://github.com/psf/black) from 19.10b0 to 20.8b1.
- [Release notes](https://github.com/psf/black/releases)
- [Changelog](https://github.com/psf/black/blob/master/CHANGES.md)
- [Commits](https://github.com/psf/black/commits)

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

* fix: run `make format`

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: PrettyWood <em.jolibois@gmail.com>

* Allow URLs without `user` part

Refer to #1877

* Update docs

* Allow Redis DSN with schema only

Refer to https://github.com/samuelcolvin/pydantic/pull/1911#issuecomment-722335692
Refer to https://www.iana.org/assignments/uri-schemes/prov/redis

* Fix lint error

* Fix lint error

* Set `parts: Dict[str, Optional[str]]` instead of `Dict[str, str]`

* Fix linting

* More verbose default values set in `RedisDsn.validate_parts()`

* Fix linting 2

* Fix typo in docs

* Add a note in the changelog

* Add test case for URL without `user` part

* change port in test

Co-authored-by: PrettyWood <em.jolibois@gmail.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Samuel Colvin <s@muelcolvin.com>
2020-12-30 18:20:51 +00:00
Eric Jolibois 3496a473c7 build(deps): bump to pytest 6.2.1, pytest-mock 3.4.0, mkdocs-material 6.1.7 and codecov-action v1.0.15 (#2201)
* build(deps): bump to pytest 6.2.1, pytest-mock 3.4.0, mkdocs-material 6.1.7 and codecov-action v1.0.15

replaces #2199, #2180 and #2164

* fix: yield_fixture is deprecated

* chore: add dotenv in optional deps
2020-12-17 23:28:07 +01:00
Rick Izzo 465f267c7d Added StrictBytes type (#2136)
* Added StrictBytes type

* updated tests for StrictBytes, updated relevant sections in documentation for StrictBytes and ConstrainedBytes

* added changelog

* chore: typo in change

Co-authored-by: Eric Jolibois <em.jolibois@gmail.com>
2020-12-01 01:18:35 +01:00
Eric Jolibois 2a82bd7ee3 chore: fix contributing steps (#2144)
Following #2030, the requirements to build the documentation are not installed
with the rest making `make docs` crash when following the contributing steps.
As `make install` is only used for this purpose (easy onboarding), let's just add
again the installation of the doc requirements with it
2020-11-30 18:02:36 +00:00
oridistor 223744da9f Updated validators.md with the type of field (#2110)
As someone started using pydantic, it can be very convenient to know what type we can rely the returned field is, so we know what we can check on it and what fields it has.
After searching the code I found out it has to be of type ModelField and that's why I'm offering it here as something that I think should be clarified in the documentation.
2020-11-30 00:01:02 +00:00
Samuel Colvin 7c3919ce4d combined version bumps (#2153) 2020-11-29 17:57:29 +00:00
Matthew Davis 9cb7ca744b add NonPositive/NonNegative Int/Float (#1987)
fix #1975

* add NonPositive/NonNegative Int/Float

* delete data.json file
2020-11-29 16:07:51 +00:00
Eric Jolibois b3f7b28f13 fix: forward all the params of the stdlib dataclass when converted into _pydantic_ dataclass (#2066)
* fix: forward all the params of the stdlib `dataclass` when converted into _pydantic_ `dataclass`

closes #2065

* add some documentation
2020-10-31 18:45:20 +00:00
milo-minderbinder 9af8f11086 fix typo in example secret filename (#2074) 2020-10-31 18:41:18 +00:00
Eric Jolibois 0b9cd4e537 fix: pydantic dataclass can inherit from stdlib dataclass and arbitrary_types_allowed is supported (#2051)
* fix: pydantic dataclasses can inherit from stdlib dataclasses

closes #2042

* docs: add some documentation

* fix: support arbitrary_types_allowed with stdlib dataclass

closes #2054

* docs: add documentation for custom types
2020-10-28 19:10:55 +00:00
Joscha Götzer fb5ea74bba Update datamodel_code_generator.md (#2058) 2020-10-28 10:18:38 +00:00
Samuel Colvin 95435de452 build history and uprev version (#2040)
* build history and uprev version

* tweak history

* add #744 to changelog

* bump
2020-10-26 11:31:10 +00:00
PrettyWood c83156d0e0 feat: make pydantic dataclass decorator support built-in dataclass (#1817)
* feat: pydantic dataclasses support built-in ones

closes #744

* feat: improve dataclass typing

* feat: add support for nested dataclasses

closes #1743

* feat: support dataclass schema with nested dataclasses

* refactor: remove `_dataclass_with_validation` function

* docs: add docstring for `make_dataclass_validator`

* refactor: rename DataclassType into Dataclass

The name `DataclassType` was missleading as it's not a `Type` per say.

* refactor: change global `dataclass` import to local

pydantic import time was improved in
https://github.com/samuelcolvin/pydantic/pull/1132
by keeping `dataclass` import local. So let's keep it that way!

* test: add extra nested case with BaseModel

* chore: s/pydantic/_pydantic_/g

* docs: add some documentation
2020-10-26 11:09:28 +00:00
mdgilene 30cd121cfe Add ability to read secrets from files (#1820)
* Add ability to read secrets from files

* Added docs and updated tests to handle new _build_values argument

* Updated docs to note which types are loaded

* Updated deep_update to take a list of update mappings

* Added warning when fields are not defined as a secret type

* Address additional PR feedback

* improve documentation

* remove redundant UserWarning lines

* allow any field type, not just SecretStr

* regex escape paths in windows 😴

* skip tests on windows 😧 🔫

Co-authored-by: Samuel Colvin <s@muelcolvin.com>
2020-10-26 10:06:25 +00:00
dependabot[bot] 52889203ac Bump devtools from 0.6.0 to 0.6.1 (#2037)
* Bump devtools from 0.6.0 to 0.6.1

Bumps [devtools](https://github.com/samuelcolvin/python-devtools) from 0.6.0 to 0.6.1.
- [Release notes](https://github.com/samuelcolvin/python-devtools/releases)
- [Changelog](https://github.com/samuelcolvin/python-devtools/blob/master/HISTORY.md)
- [Commits](https://github.com/samuelcolvin/python-devtools/compare/v0.6...v0.6.1)

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

* remove unnecessary dependencies

* tweaks while testing 3.9

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Samuel Colvin <s@muelcolvin.com>
2020-10-26 09:53:28 +00:00
Arseny Boykov 664cbcfc01 Add private attributes support (#1679)
* Add private attributes support

* Add more blank lines in example

* Add changes file

* Update docs/usage/models.md

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

* fix after bad merge

* Add PrivateAttr, Config.underscore_attrs_are_private

* remove unrelated change in utils.py

* add   # noqa: C901 (ignore complexity) to __setattr__
(see comment in PR)

* add annotation to Config.underscore_attrs_are_private

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

* use sunder names

* mention underscore_attrs_are_private in model_config.md

* add comment about default factory

* fix comment

* fix comment

* clarify that both dunder and sunder names might be used

* tweak docs and name

* _set_default_private_attributes -> _init_private_attributes

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

* use new name _init_private_attributes

* move tests

* copy private attributes in BaseModel.copy()

* add test for default and default_factory used together

* fix linting

* more tests, default_factory kw only

Co-authored-by: Samuel Colvin <samcolvin@gmail.com>
Co-authored-by: Samuel Colvin <s@muelcolvin.com>
2020-10-26 09:47:40 +00:00
Chris Hoogeboom 0af5e5f559 Allow generics to extend concrete classes. fixes #2005 (#2006)
* Allow generics to extend concrete classes. fixes #2005

* Update the docs

* Updote the changes

* Convert double quotes to single quotes

* Fix formatting

* Add a check for data

* Update example

* Add a skip_36 decorator that got accidentally deleted when resolving conflicts.
2020-10-25 19:22:25 +00:00
Benjamin Sitruk e00dba322b Docs: Add validators to dynamic model (#1963)
* Add dynamic validators to doc

* Update models_dynamic_validators.py

* Update models_dynamic_validators.py

* Adding example (success and error)

* Update models_dynamic_validators.py
2020-10-25 17:57:08 +00:00
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
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
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
dependabot[bot] c4986ded1c Bump markdown from 3.3 to 3.3.1 (#2016)
Bumps [markdown](https://github.com/Python-Markdown/markdown) from 3.3 to 3.3.1.
- [Release notes](https://github.com/Python-Markdown/markdown/releases)
- [Commits](https://github.com/Python-Markdown/markdown/compare/3.3...3.3.1)

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

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2020-10-25 12:16:28 +00:00
dependabot[bot] 893fb8b6a0 Bump mkdocs-material from 6.0.2 to 6.1.0 (#2015)
Bumps [mkdocs-material](https://github.com/squidfunk/mkdocs-material) from 6.0.2 to 6.1.0.
- [Release notes](https://github.com/squidfunk/mkdocs-material/releases)
- [Changelog](https://github.com/squidfunk/mkdocs-material/blob/master/docs/changelog.md)
- [Commits](https://github.com/squidfunk/mkdocs-material/compare/6.0.2...6.1.0)

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

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2020-10-25 12:16:14 +00: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
Samuel Colvin 8ccc5708f1 remove data.json, fix #1992 (#1994) 2020-10-11 19:34:37 +01:00
Jason Wu 130c9903d7 docs: fix typo (#1959) 2020-10-09 13:06:47 +01:00
Stefan Götz 9d4ba6d4b5 - fix typo in docs/index.md (#1921) 2020-10-09 12:52:08 +01:00
Brian Maissy dbb1ed0aaa remove strict_optional from sample mypy.ini in doc (#1830)
Really not critical, but strict_optional=True is the default for mypy since 0.600, so its presence in the sample mypy.ini in the docs seems redundant.

https://mypy.readthedocs.io/en/stable/command_line.html#cmdoption-mypy-no-strict-optional
2020-10-09 11:28:42 +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
Samuel Colvin c5fc921620 combined uprev of dependencies (#1978) 2020-10-09 10:20:36 +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
PrettyWood 55e78cc106 fix(schema): add basic support of Pattern type in schema generation (#1768)
closes #1767
2020-10-08 20:42:14 +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
Samuel Colvin 296d929904 updating all deps (#1907)
* updating all deps

* uprev github actions docs
2020-09-06 13:04:41 +01:00
Jordan Côté f1f944fbc1 Update datamode_code_generator:typo in pip install (#1713)
As seen in https://koxudaxi.github.io/datamodel-code-generator, the correct command is 
`pip install datamodel-code-generator`
not
`pip install datamodel-code-generato`
2020-07-13 18:33:48 +01:00
Lordran 527c35a856 remove duplicate "an" (#1708) 2020-07-11 11:23:29 +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
dependabot-preview[bot] dc72ae00a3 Bump mkdocs-material from 5.3.3 to 5.4.0 (#1672)
Bumps [mkdocs-material](https://github.com/squidfunk/mkdocs-material) from 5.3.3 to 5.4.0.
- [Release notes](https://github.com/squidfunk/mkdocs-material/releases)
- [Changelog](https://github.com/squidfunk/mkdocs-material/blob/master/CHANGELOG)
- [Commits](https://github.com/squidfunk/mkdocs-material/compare/5.3.3...5.4.0)

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

Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
2020-07-03 20:44:47 +01:00
Yuri Khan 259a1a0ff8 Fix typo (#1631) (#1674) 2020-07-01 14:47:44 +01:00
Yuri Khan 908f6edb72 Document default regex anchoring semantics (#1631) (#1648) 2020-06-27 19:16:32 +01:00
Yuri Khan d5e1c88fda Document schema_extra calling convention (#1645) 2020-06-27 18:53:59 +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 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 f85afab8cf tiny correction to docs 2020-06-27 13:58:23 +01:00