Commit Graph

84 Commits

Author SHA1 Message Date
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
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
Jason Wu 130c9903d7 docs: fix typo (#1959) 2020-10-09 13:06:47 +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
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
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
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
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
Samuel Colvin d122b1dbdc remove RedisDsn.user_required = True (#1658)
* remove RedisDsn.user_required = True

* update docs
2020-06-26 12:02:57 +01:00
Fredrik Jonsén 97b6b46268 docs: add missing period and capitalize where appropriate (#1653) 2020-06-23 18:47:39 +01:00
PrettyWood 0cee311be5 feat(settings): allow custom encoding for dotenv files (#1620)
closes #1615
2020-06-11 11:04:08 +01:00
Samuel Colvin 63ec6fffe3 update docs on generics, fix #1547 (#1584) 2020-05-31 15:08:57 +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
Luka Peschke 1bff80459d Add an example to documentation for reserved ORM field names (#1474)
Signed-off-by: Luka Peschke <mail@lukapeschke.com>
2020-05-31 14:44:23 +01:00
Mike Grima 28c2ac7a43 Added docs on dumping dataclasses to JSON (#1487) 2020-05-18 21:55:49 +01:00
Selim Belhaouane 881df8bde7 move const validator to post validators. fixes #1410 (#1446) 2020-04-30 19:05:42 +01:00
Jerry 9b2310a7d3 Fixed typo (#1456)
stictness -> strictness
2020-04-30 13:06:53 +01:00
Samuel Colvin 67acb659c2 prepare v1.5 release 2020-04-18 17:32:16 +01:00
Stephen Brown II cab6313798 Allow subclasses of known types to be encoded with superclass encoder (#1291)
* Add (failing) test for Subclass JSON encoding

* Allow subclasses of known types to be encoded with superclass encoder

* Add change file

* Add documentation, fix custom json_encoders and add unit test

Blacken doc
Fix test that worked on my machine
datetime.timestamp() is flakey?
Single quotes only

* Reduce lookups

- Remove last element in `__mro__` as it will always be `object`
- Use .get for compactness

* Regarding the loop

* Move Path and Enum into ENCODERS_BY_TYPE

Sort ENCODERS_BY_TYPE

* improve JSON docs

Co-authored-by: Samuel Colvin <s@muelcolvin.com>
2020-04-18 17:11:00 +01:00
Samuel Colvin ec25f60d27 correct name of validate_arguments in docs (#1375)
* correct naem of validate_arguments in docs

* bump

* Update docs/usage/validation_decorator.md

Co-Authored-By: Stephen Brown II <Stephen.Brown2@gmail.com>

* Apply suggestions from code review

Co-Authored-By: Stephen Brown II <Stephen.Brown2@gmail.com>

Co-authored-by: Stephen Brown II <Stephen.Brown2@gmail.com>
2020-04-18 16:10:58 +01:00
Atheuz 097762b67a make secret types idempotent (#1330)
* make secret types idempotent

* remove idempotent from secret types example.
add note to docs for idempotently creating secret types.
use isinstance for comparing when creating secret types idempotently.
add assert for idempotent secret types test.

* tweaks

Co-authored-by: Lasse Gravesen <lasse.gravesen@falcon.io>
Co-authored-by: Samuel Colvin <s@muelcolvin.com>
2020-04-18 16:10:36 +01:00
mikuhn 91c626eee0 docs: add hint for custom root types (#1373)
fix #1372

Co-authored-by: Michael Kuhn <michael.kuhn@uni-tuebingen.de>
2020-04-15 22:53:19 +01:00
Michael (Misha) Salim ebb2e6c942 Use __all__ to exclude fields from all elements of a list/tuple of submodels. Raise more informative TypeError when passing bad exclude kwargs. (#1286)
* Raise informative TypeError when passing bad exclude kwargs to export

* Cleanup spurious example

* Add __all__ keyword to enable excluding fields from all members of a list/tuple of child submodels

* Add changelog

* Fix MD format inconsistencies and consolidate export tests

* Excluding from exported List of Dict fields with "__all__"

* tweaks

Co-authored-by: Samuel Colvin <s@muelcolvin.com>
2020-03-18 20:22:49 +00:00
PrettyWood 78a3f42b0a Dynamic default value (#1210)
* Simplify dynamic default values

closes #866

* Add documentation and change

* Add `ModelField.get_default` method

* Fix default value in `infer`

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

Co-authored-by: Samuel Colvin <samcolvin@gmail.com>
2020-03-04 16:37:23 +00:00
Thaïs de Boisfossé 679e5d149e Generics inherit doc (#1249)
* doc: add an example of inheritance with Generics

* Update the changes directory with the doc changes.
2020-03-04 15:40:04 +00:00
Arseny Boykov 0f948618ba Add model signature generation (#1034)
* Add right __init__ signature generation

* Add params overlay support for custom __init__, enhance tests

* Change fake_ini creation to solve AttributeError in cython
AttributeError: attribute '__code__' of 'cython_function_or_method' objects is not writable
Possible there's other attrs that cannot be set in cython, but can't check myself yet

* Cython compatibility, add __signature__, ignore non-identifiers fields
Moved tests to separate file
Moved __init__ creation to utils

* Remove # pragma: no cover

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

* Fixed adding signature to doc, some compatibility fixes

* Changed None to tuple() for py3.8 compatibility

* Finally (hope so) fix issues with closure. Add new docstring each time

* coverage for UndefinedType

* Checking signature more simple and obvious way

* Changed doc caption to simple message, used Undefined, merge conflicts

* Compatibility with py3.6

* Add changes/ file

* Ah, that space... Reformatted and ready to go!

* Update pydantic/main.py

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

* Update pydantic/main.py

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

* Fix signature for properties declared as fields

* Sort imports

* Add comments

* Generate BaseModel signature instead of __init__ signature

* Fixed imports

* Minor improvements from review

* Add docs for model signature

* Delete unused imports

* Fix formatting in tests

* Remove inspect imports from top level

* Update docs/examples/models_signature.py

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

* Add missing import

* Remove notes from doc

* change hypothesis-auto mention to hypothesis

* Use None as slice end instead of len()

* tweak generate_model_signature

* improve docs

* Revert af3dd4d, add fields to custom init only if var_kw declared

Co-authored-by: Samuel Colvin <samcolvin@gmail.com>
2020-02-27 17:35:51 -05:00
Samuel Colvin 6914410f38 Validation Decorator (#1179)
* starting validation_decorator

* correct skip_pre_38

* fix coverage and type hints

* mypy tests and move to class based decorator

* 3.6 fix, prevent duplicate github actions

* correct py 3.6 check

* better errors

* cleaner field names for args and kwargs

* add change and comments

* starting docs

* back to 3.7 for docs

* docs

* bump

* add async example and fix print indents

* allow type annotations as strings

* python 3.8 in docs
2020-02-05 17:27:12 +00:00
Wesley Ellis be95ddaf88 Be more specific about the meaning of Config.extra (#1203)
* Be more specific about the meaning of Config.extra

When reading through the docs as a beginner, it was not clear to me what the difference between `'allow'` and `'ignore'` was. I fixed this by adding a short description of each of the options from what I can tell from reading the source code.

Is there a better way to format this? Maybe as a list?


(ps, thanks for the cool library)

* tiny further clarification

* sorry...

Co-authored-by: Samuel Colvin <samcolvin@gmail.com>
2020-02-02 12:15:42 +00:00
Samuel Colvin 943a8a06e5 change alias priority logic (#1178)
* fix alias priority so alias_generators don't take priority

* improve test names

* remove debugs

* Apply suggestions from code review

* more tests and allow custom alias_priority on fields

* precedence tests and docs

* tweaks and add change

* suggestions
2020-01-24 10:31:16 +00:00
Ishan Anand 2c5a8093b8 add note about diff bw pydantic and stdlib dataclasses (#1188)
fix #1187
2020-01-24 10:10:08 +00:00
James Curtin b7c0dd5b16 Support unicode and punycode when validating TLDs (#1183)
* Support unicode and punycode when validating TLDs

* Consolidate HTTP internationalization logic
2020-01-21 16:55:11 +00:00
Samuel Colvin 02784fb83b docs typo 2020-01-19 18:28:11 +00:00
Connor 730d84217d allow use of a .env-style files in BaseSettings (#607) (#1011)
* allow use of a `.env`-style files in BaseSettings (#607)

* address various issues with initial implementation

- allow specifying `_env_file` kwarg in instantiation
  * overrides any `env_file` specified in the `Config` class
- cast `os.environ` as a dict for better consistenty of behavior
- `env_path` should be a `Path` type
- replace `with open()` with `read_text`
- use regex for parsing the dotenv files and throw error on invalid line
- factor out `read_env_file` into separate file for easier testing

* move back into a single file; revert typing changes; use regex better

* pass `_env_file` argument around instead of setting a class attribute

* add dotenv docs

* add dotenv tests

* Add changes file

* Flesh out the docs a bit

* Apply suggestions from @samuelcolvin's code review

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

* wrap docs

* add not about priority

* fix tests and imports

* fix tests

* switch to python-dotenv

* cleanup, test example

* more docs tweaks

* typo

* fix tests for dotenv

Co-authored-by: Samuel Colvin <samcolvin@gmail.com>
2020-01-19 16:45:36 +00:00
Sebastián Ramírez aeba494388 Add support for generics with __get_validators__ (#1159)
*  Add support for generics with __get_validators__

*  Add tests for Generics with __get_validators__

* 📝 Add change note

*  Add support for Generic fields with validation of sub-types

* 📝 Add docs for arbitrary generic types

*  Add tests for generic sub-type validation

* 📝 Update change note. Generic support is not so "basic" now

* 📝 Update docs with code review

* ♻️ Update fields module with code review changes

*  Update tests from code review

* 📝 Update example for generics, try to simplify and explain better

* tweak docs example

Co-authored-by: Samuel Colvin <samcolvin@gmail.com>
2020-01-17 16:22:54 +00:00
Sebastián Ramírez 496551c854 Implement support for declaring infinite generators (#1152)
*  Implement support for infinite generators with Iterable

*  Add tests for infinite generators

* 🎨 Fix format

* 📝 Add docs for infinite generators

* 📝 Add changes file

*  Store sub_field with original type parameter to allow custom validation

* 📝 Add example for validating first value in infinite generators

* 🔥 Remove unused import in example

*  Add test for infinite generator with first-value validation

* ♻️ Update fields with code review

* 📝 Update example from code review

* 📝 Update docs and format from code review
2020-01-13 11:50:16 +00:00
David Montague dbc044e357 Add support for nested generics (#1104)
* Add support for nested generics

* Allow instantiation of unparameterized generics

* Add better more partial instantiation tests

* Add changes

* Add docs
2020-01-10 21:06:52 +00:00
pmav99 8a53350412 docs: Add docs for allow_reuse (#1135)
* docs: Remove trailing whitespace

* docs: Add docs for "allow_reuse"
2020-01-02 15:13:44 +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