Commit Graph

29 Commits

Author SHA1 Message Date
Samuel Colvin 62bb2ad492 allow Config.field to update a Field (#2461)
* allow Config.field to update a Field, fix #2426

* move logic to update_from_config, work with Annotated

* fix flake8 erroneous warnings

* test for allow_mutation

* better support for allow_mutation
2021-03-03 16:52:37 +00:00
Eric Jolibois 3ec35590f1 Support Field in dataclass + 'metadata' kwarg of dataclasses.field (#2384)
* Support `Field` in `dataclass` + `'metadata'` kwarg of `dataclasses.field`

Please enter the commit message for your changes. Lines starting

* add `__has_field_info_default__` for minimal effect on perf

* lower complexity of `_process_class`
2021-02-25 20:04:16 +00:00
Eric Jolibois d0baf0f156 fix(fields): handle properly default value for type Callable (#2094)
* fix(fields): handle properly default value for type `Callable`

closes #1596

* chore: move test in test_dataclasses

* chore: add comments

* test: rewrite test

* chore: remove useless variable

* fix(schema): add support when callable field has default value

closes #2086
2021-02-11 11:39:09 +00:00
Eric Jolibois c18634b42a fix: required fields default value is the same for static and dynamic models (#2167)
* revert logic of #2143

* rewrite logic removed in #1755

* test: add test to ensure dynamic and static behaviours are the same
2021-01-01 14:20:49 +00:00
aimestereo 35fde4e216 Fix #2111: support pickle for built-in dataclasses (#2114)
* 2111: support pickle for built-in dataclasses

* 2111: add changes

* 2111: simplify test

* return original name + handle similar names

* add additional check

* fix a misspell

* remove useless f-string

* cleanup test

Co-authored-by: Samuel Colvin <s@muelcolvin.com>
2020-11-30 19:28:14 +00:00
Eric Jolibois c0ac53b757 fix: set right default value for required (optional) fields (#2143)
closes #2142
2020-11-30 17:55:50 +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
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
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
John Carter 827388b4fe Add a test assertion that default_factory can return a singleton (#1523) 2020-05-31 14:51:50 +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
George Sakkis b749e224c9 Allow None for (virtual) superclasses of NoneType (#1266)
* Set allow_none to True for (virtual) superclasses of NoneType

* Add full support for Hashable
2020-04-15 16:45:23 +01:00
Alexander Hirner c188b3fba8 Feature/dataclass schema defaults (#980)
* default dataclass field from default_factory

* silence mypy regarding issue 708

* test dataclass factory function default

* test default factory ending up in schema

* add changes md

* add docs for dataclass default factory and basemodel access

* fully print default factory schema
2019-11-09 12:29:15 +00:00
Samuel Colvin 6e5a1363cc V0.32 merge (#852)
* fix(validate-assignment): do not validate extra fields when `vaidate_assignment` is on

* Update history

* Fix `value` vs. `value_`

* Add tests for `value` vs `value_` case

* uprev

* Fix generic required (#742)

* Fix required fields on GenericModel

* lint

* version up

* __post_init__ with inheritance, fix #739 (#740)

* Fix custom Schema on GenericModel fields (#754)

* Fix custom Schema on GenericModel fields

* Add PR#

* uprev

* Fix error messages for Literal types with multiple allowed values (#770)

* Fix error messages for Literal types with multiple allowed values

* Incorporate feedback

* update history
2019-10-01 17:22:05 +01:00
Scott P 5015a7e48b Improve auto-generated title in JSON schemas (#772)
* Improve auto-generated title in JSON schemas

Underscore is converted to space.

* Added changes .rst file.
2019-08-21 16:49:05 +01:00
Daniel Petti aa5e8c60b7 Feature/frozenset support (#762)
* Better error for unsuported "typing" objects.

Fixes #745

Add a better error message for fields with types from the typing
module that are not directly supported by Pydantic. Previously,
it caused a cryptic assertion failure.

* Add support for frozenset fields.

Also provide an example of their usage.

Fixes #745

* Address review comments.

Fixes #745

* use equals not "is" for int comparison.
2019-08-21 13:13:46 +01:00
Raphael de Carvalho Almeida 5b5451c02e Added initvars support to post_init_post_parse (#748)
* Added initvars support to post_init_post_parse

* Update change log with PR number

* Add practical initvars example to tests

* Update documentation
2019-08-16 09:36:56 +01:00
Samuel Colvin 461b852e4e enforcing single quotes (#612)
* enforcing single quotes

* update history
2019-06-21 12:32:03 +01:00
秋葉 6233554394 fix __post_init__ cause infinite recursion in inheritance (#606)
* fix __post_init__ cause infinite recursion in inheritance

* update changelog

* update code quote

* rename instance to self

* Update HISTORY.rst

Co-Authored-By: Samuel Colvin <samcolvin@gmail.com>
2019-06-21 10:46:21 +01:00
pfrederiks b77da1ec9e Add support for InitVar (#591)
* Add support for InitVar

* Annotate *initvars as Any

* Simplify tests

* Add line to HISTORY.rst

* Use dataclasses.fields which also ignores ClassVars

* tweak history
2019-06-14 16:56:08 +01:00
Sebastiaan Van Hoecke 2a04aa76b0 added feature post_init_post_parse (#567)
* added feature post_init_post_parse

* fixed bug where post_init_post_parse was triggered without looking is post_init_original is set

* change double to single quotes

* __doc__ strings fixed back to double quote

* added better way of doing the post_init_post_parse also tests passes now

* removed unused file

* deleted unnecessary test

* update history.rst, changed previouis change 560 to breaking change because it broke the original flow

* update docs, added section post_init_post_parse under dataclasses

* added __post_init_post_parse__ as attribute of DataclassType

* Update HISTORY.rst

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

* Update HISTORY.rst

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

* Update pydantic/dataclasses.py

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

* update docs, added subsection initialize hooks under dataclasses

* my bad

* make tests work again

* removed checking if post_init_parse is none

* correct typo in history

* fixed typo in history.rst
2019-06-04 10:01:09 +01:00
Vítor Augusto da Silva Vasconcellos 79ed78fda0 Run dataclass' original __post_init__ before validation (#560)
* Run dataclass' original __post_init__ before validation

* Add unit test

* Update HISTORY.rst
2019-05-29 18:14:36 +01:00
NoAnyLove 2ca81ed33f Fix nested dataclass schema (#475)
* Add test case for nested dataclass schema, fix #474

* Fix nested dataclass schema

* Fix mypy typing

* Update HISTORY.rst

* Code review updates
2019-04-18 10:10:36 +01:00
Vitaly R. Samigullin caaa16ee71 Dataclass schema attr (#438)
fix #408

* Fix default field value compatibility for dataclass-based models

* Add unittests for dataclass schema bugfix

* Update HISTORY
2019-03-28 12:56:58 +00:00
Samuel Colvin 8301f9e4b2 dataclass validation (#334)
* dataclass validation, fix #273

* support for tuple or dict in dataclasses

* tweaks

* adding example in docs
2018-12-27 19:15:39 +00:00
jarekkar 72791787ea Add support for passing Configs to Dataclasses (#285)
* Add support for passing Configs to Dataclasses

* formatting and fixes

* move tests into dataclasses_config.py

* use inherit_config in create_model

fix #276
2018-12-27 17:54:17 +00:00
Samuel Colvin b5fdc0db1e dataclass inheritance, fix #293 (#299) 2018-11-15 12:28:03 +00:00
Samuel Colvin 15850a43c5 moving to black (#287)
* moving to black

* put back flake8

* remove isort option

* putting back isort

* uprev pycodestyle

* remove black from docs/examples

* tweak parse.py
2018-11-15 11:30:07 +00:00
Samuel Colvin f3a278bb8d Dataclasses (#269)
* pydantic.dataclasses.dataclass decorator

* add dataclasses to requirnment.txt

* reimplement dataclasses

* fix linting, fix coverage

* docs
2018-10-01 09:48:28 +01:00