Commit Graph

184 Commits

Author SHA1 Message Date
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
Alexander Hultnér 2eb62a3b2f Added a "Talks and video tutorials" section (#1499)
* Added a "Talks and video tutorials" section

Added my "Python pydantic Introduction – Give your data classes super powers" talk YouTube video based on the talk for Python Pizza.

* Add changelog entry for video change

Did this after creating the pr so I would have the number to use as a reference.

* Moved video into a discussion subsection

Now placed under testimonials

* Updated change log entry to reflect changes.
2020-05-26 07:50:56 +01:00
Calvin Young 5195e55c10 Enums as separate models (#1432)
* Updates schema() to generate enums as separate models

* Fixes mypy annotations

* Adds changes file

* Fixes comment

* Removes unused import

* Fixes test case

* Fixes missing partial branch in test coverage

* Resolves PR comments

* 🐛 Include enums in flat model schema handling

as they now have independent schemas, they kinda behave like top-level models, and should be taken into account for top level definitions

*  Add test for coverage

* 🐛 Use Type[Enum] as type for consistency

Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
2020-05-23 19:11:34 +01:00
Daniel Burkhardt Cerigo 913025ac3f FIX: validation on model attribute with nested Literal breaks (#1364)
* Add tests for nested literals validator

* Implement flatten literal in validator

* Add test for flatten literal

* Add changelog entry

* Add test skip markers if not Literal

* Refactor: use improved all literals implementation

From Github user PrettyWood, see PR https://github.com/samuelcolvin/pydantic/pull/1364

* Add testing for typing module

Includes moving corresponding tests.

* Remove unnecessary type hint

* Move all literals test to test_utils
2020-05-23 13:01:43 +01:00
Stephen Bunn 1eeb225c67 Fix NameEmail equality comparison (#1527)
* Adding appropriate __eq__ method for NameEmail

- Introducing new test assertions for NameEmail

Signed-off-by: Stephen Bunn <stephen@bunn.io>

* Adding change doc for NameEmail.__eq__

Signed-off-by: Stephen Bunn <stephen@bunn.io>

* Update pydantic/networks.py

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

* Update tests/test_networks.py

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

* Fixing indentation issue left over from suggestion

Signed-off-by: Stephen Bunn <stephen@bunn.io>

Co-authored-by: Samuel Colvin <samcolvin@gmail.com>
2020-05-19 08:59:33 +01:00
Mike Grima 28c2ac7a43 Added docs on dumping dataclasses to JSON (#1487) 2020-05-18 21:55:49 +01:00
Arseny Boykov 0b9b308ca5 Make signature class only (#1466)
* Make signature class only

* Add changes file
2020-05-18 21:41:24 +01:00
Selim Belhaouane 881df8bde7 move const validator to post validators. fixes #1410 (#1446) 2020-04-30 19:05:42 +01:00
Mostapha Sadeghipour Roudsari a4adf892dc Remove extra allOf keys in schema (#1438)
resolves #1209
2020-04-30 18:56:11 +01:00
Atheuz 9238e3d98f include format with secret types (#1424)
* include format with secret types

* fix: fix pr comments.

Co-authored-by: Lasse Gravesen <lasse.gravesen@falcon.io>
2020-04-30 13:09:45 +01:00
Jesse VanderWees 833d33dc0f ConstrainedFloat schema: differences between IEEE floats and json (#1422)
* ConstrainedFloat schema: account for differences between IEEE floats and json

* add changes

* Update changes/1417-vdwees.md

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

* Update changes/1417-vdwees.md

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

* fixup

* Update pydantic/types.py

Difference of styles :)

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

* merge _schema_ieee_compatibility_transform into parent method

* capitalize

* use type_, not outer_type_

Co-authored-by: Jesse VanderWees <jesse.vanderwees@kisters-bv.nl>
Co-authored-by: Samuel Colvin <samcolvin@gmail.com>
2020-04-30 13:08:23 +01:00
Samuel Colvin f96c4dc59f uprev 2020-04-23 13:43:34 +01:00
PrettyWood b2871468b7 Fix :: Signature generation with extra: allow never uses a field name (#1420)
* fix :: signature generation does not use field names

fix #1418

* fix :: use field.outer_type_ when generating signature

`extra_data: Dict[str, str]` would generate `extra_data: str` in the signature

* tweak to keep signature kwargs name

Co-authored-by: Samuel Colvin <s@muelcolvin.com>
2020-04-23 13:42:06 +01:00
PrettyWood 3cd8b1ee2d Fix :: avoid mutating Field default value (#1413)
fix #1412
2020-04-22 11:25:13 +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
AlexECX 52af916206 Prevent mutation of excludes/includes (#1404)
* Don't mutate excludes/includes dictionaries inside ValueItems

* Make exludes/includes read-only

* Add changelog

* Update 1404-AlexECX.md

* Add test for includes/excludes immutability
2020-04-18 17:09:06 +01:00
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