Commit Graph

150 Commits

Author SHA1 Message Date
AlexECX 92b0bbc0f3 Bug fix: excludes skipped for aliased nested fields when by_alias=True (#1398)
* Typo in test function name, fix #1397

* Always use a field's real name for includes/excludes

* Add changes.md file
2020-04-18 17:05:20 +01:00
Lance McNearney 161a12a1a1 Update constr regex example to include start and end lines (#1400)
This is due to the regex using `re.match()` which allows for only a partial match, fix #1396
2020-04-18 17:02:22 +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
Samuel Colvin 9a8bda5b16 confirm shallow copy works as expected, (#1394)
* confirm shallow copy works as expected, fix #1383

* fix linting
2020-04-15 22:58:56 +01:00
Kittipat Virochsiri c5af109e57 Fix argument name collision (#1367)
fix #1366

* Fix argument name collision

* change qoutes

* make mypy happy?

* Adding change file
2020-04-15 22:52:07 +01:00
Dima Boger ccd5f7b8f3 Replace exception to silent passing in mypy plugin for non-Var attributes (#1348)
* Replace exception to silent passing in mypy plugin for non-Var attributes

* Add a history file
2020-04-15 22:46:22 +01:00
PrettyWood 2c05415bae accept None as value for all optional fields (#1307)
* ignore pyenv generated file

* Allow `None` as input to all optional list fields

* skip test on python 3.6

* fix mypy error, line length

Co-authored-by: Samuel Colvin <s@muelcolvin.com>
2020-04-15 22:43:38 +01:00
Danny Weinberg a015cd01ba Have BaseModel inherit from Representation (#1319)
* Have BaseModel inherit from Representation

This changes the inheritance so that `BaseModel` *actually* inherits from `Representation`, rather than just having the same methods as it. While this doesn't actually affect the runtime, it does make mypy happier.

Fixes https://github.com/samuelcolvin/pydantic/issues/1310

* Add '__dict__' back into slots
2020-04-15 22:07:16 +01:00
Atheuz 7cc5dbeb6a document making secret types dumpable using the json method (#1328)
Co-authored-by: Lasse Gravesen <lasse.gravesen@falcon.io>
2020-04-15 22:05:43 +01:00
PrettyWood aaec3c9c15 Remove typing-extension dependency on python 3.8 (#1342)
* Remove typing-extension dependency on python 3.8

* retrigger CI

* retrigger CI bis
2020-03-26 15:44:11 +00:00
Samuel Colvin 3f04bb3200 fix card number length check in PaymentCardNumber (#1321)
* fix card number length check in PaymentCardNumber

* add check for PaymentCardBrand str()
2020-03-21 17:08:08 +00:00
Samuel Colvin 96c9c400bc Move to GitHub actions (#1326)
* trying move to github actions

* move name

* remove travis and cleanup

* macos and windows coverage

* env_vars string

* bump

* bump

* delete old coverage file

* remove coverage.xml

* add 'make test-codecov'

* fix 'make test-codecov'

* beginning build phase

* combined deploy

* try to fix articacts

* remove set.cfg wheel tag

* install cython before build

* fix windows builds

* fix windows builds

* reenable tests

* build docs, test pypi upload

* finalize

* add change description, fix job conditionals
2020-03-21 17:02:07 +00:00
Stephen Brown II 13b002e97f Add datetime field to default_factory example (#1301)
* Add change file

* Add datetime field to default_factory example

Print instead of assert
Remove bad quotes
Remove bad quotes from all examples

* fix change description

* remove 'avoid-escape' from setup.cfg

Co-authored-by: Samuel Colvin <s@muelcolvin.com>
2020-03-18 20:23:42 +00: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
Samuel Colvin e57f777c4d Support instance methods and class methods with @validate_arguments (#1272) 2020-03-17 20:12:30 +00:00
Pavel Ilyin d8262131d2 No dict update (#1244)
* update_forward_refs now modifies only a copy of __dict__ of cls.__module__

* changes

* test for update_forward_refs

* fixed brackets

* black changes fixed

* make format

Co-authored-by: Samuel Colvin <s@muelcolvin.com>
2020-03-17 19:57:13 +00:00
Alexei Robyn d1279e865e Fix parsing nested custom root type models (#1253) 2020-03-17 19:55:48 +00:00
adamgreg 6f4945d84c Accept pre-compiled Pattern objects (#1238)
* Change str_validator() return type to str

* Make pattern_validator() accept pre-compiled Pattern objects.

Resolves #1237.

* fix str_validator return type

Co-authored-by: Samuel Colvin <samcolvin@gmail.com>
2020-03-04 17:27:16 +00:00
Ondrej Kokes ddc8e5a57b Fix type annotations in examples (#1248)
* README change to make type annotations valid

* example fixed to have valid type annotations

* changes description

* Update README.md

explicit assignment for an optional field

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

* Update docs/examples/index_main.py

explicit assignment for an optional field

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

Co-authored-by: Samuel Colvin <samcolvin@gmail.com>
2020-03-04 17:26:11 +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
Jocelyn Boullier f2f83bcae2 Add support for NewType of List, Optional, etc. (#1208)
* add support for NewType of List, Optional, etc.

* bump

Co-authored-by: Samuel Colvin <samcolvin@gmail.com>
2020-02-27 17:14:53 -05:00
Arseny Boykov 7d9614e3f8 Refactor ._iter() method, 10x speed boost for dict(model) (#1017)
* Refactor ._iter() method:
Moved all keys-related stuff (include, exclude, etc.) to ._iter()
Removed redundant iteration through default values
Almost all arguments checks moved out of loops, so checks happen once
Fast yield from .__dict__ on plain .iter() (x10 boost)
Removed redundant set(dict.keys()) in ._calculate_keys()

* Moved back from nested generator checks to checks, optimized copy a bit

* Bump pytest-mock from 1.12.0 to 1.12.1 (#1018)

Bumps [pytest-mock](https://github.com/pytest-dev/pytest-mock) from 1.12.0 to 1.12.1.
- [Release notes](https://github.com/pytest-dev/pytest-mock/releases)
- [Changelog](https://github.com/pytest-dev/pytest-mock/blob/master/CHANGELOG.rst)
- [Commits](https://github.com/pytest-dev/pytest-mock/compare/v1.12.0...v1.12.1)

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

* __str__ and __repr__ inheritance for models, fix #1022 (#1023)

* 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

* Bump twine from 3.0.0 to 3.1.0 (#1029)

Bumps [twine](https://github.com/pypa/twine) from 3.0.0 to 3.1.0.
- [Release notes](https://github.com/pypa/twine/releases)
- [Changelog](https://github.com/pypa/twine/blob/master/docs/changelog.rst)
- [Commits](https://github.com/pypa/twine/compare/3.0.0...3.1.0)

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

* 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

* 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

* 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

* 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

* Add changes file

* Delete unrelated files

* Add check that k in fields before using alias

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

* Remove redundant call to __iter__

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

* Use typing.AbstractSet

* Update pydantic/main.py

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

Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
Co-authored-by: Samuel Colvin <samcolvin@gmail.com>
Co-authored-by: Colin Sullivan <csullivan@brandwatch.com>
Co-authored-by: David Montague <35119617+dmontagu@users.noreply.github.com>
2020-02-27 15:21:22 -05:00
Leo Sussan c4e42746f3 add pydantic.color.Color objects as available input for Color fields (#1258)
* feat: add pydantic.color.Color as available type for Pydantic color fields

* chore: test for color

* chore: change md

* fix: assertion is incorrect

* fix: logic on _original assignment

* fix: value is set to value._original in the isinstance conditional
fix: remove ._original conditional (logic is set earlier in the method)
fix: removed pydantic.color.Color line from errorstring

* chore: revert error message adjust

* chore: grammaer ;)
2020-02-26 15:25:24 -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
Samuel Colvin 55f7d35727 update root_validator signature, fix #1192 (#1204) 2020-02-01 16:59:32 +00:00
Samuel Colvin e4cd9d2c87 uprev 2020-01-24 10:48:44 +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
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
cuencandres 4f8f939690 Complete Luhn algorithm (#1167)
* Luhn algorithm bug fixed

* Robust tests for payment card number

* changes file

* Robust tests for Luhn algorithm

* remove bad quotes

* Styling changes done

* Some little changes
2020-01-20 18:53:18 +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
Samuel Colvin e2533e04c9 regex for username and password in URLs (#1175)
* regex for username and password in URLs, fix #1115

* fix linting
2020-01-17 17:13:55 +00:00
Samuel Colvin 0b5ccffc76 Fix argument in validators during assignment, fix #1172 (#1174) 2020-01-17 16:30:21 +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
Samuel Colvin fa8aa12a3d correct url_regex, fix #1142 (#1148) 2020-01-08 10:21:44 +00:00
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