Commit Graph

17 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 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
Arseny Boykov 6b53cabe03 Add pickle support to dynamically created models and generics (#1686)
* Add pickle support to dynamically created models

* Add created model module check

* Use globals() to retrieve model

* Use single quotes

* use mocker instead of mock

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

* remove unused import

* add test for dynamic forward ref

* move generic test to test_generics.py

* fix test_generic_model_pickle test, add additional check for <locals> in create_model

* fix code style

* resolve issues with global/local models

* make ensure_picklable return given model

* remove ensure_picklable, use test_is_call_from_module only in generics

* reformat code after updating black==20.8b1

* move get_caller_module_name and is_call_from_module to generics

* apply suggestions from @samuelcolvin

* add tests for get_caller_module and is_call_from_module called from module

* fix linting

* fix path to modules in test_module fixture, capture stderr and stdout

* fix broken test module

* fix subprocess call for windows

* enhance create_module fixture, add run_as_module fixture

this will allow run modules in subprocess and define module code in functions-containers

* add test for redefined concrete model without cache

* add changes file

* remove unused variable

* rewrite tests with pytest.raises

* fix linting

* rewrite test_create_model_pickle and test_forward_ref_with_create_model with module definition in function

* Update create_model docstring

Co-authored-by: PrettyWood <em.jolibois@gmail.com>
Co-authored-by: Samuel Colvin <s@muelcolvin.com>
2020-10-18 20:55:44 +01:00
Or Carmi 9900c7f00c Refactored extra types to use a single enum (#352)
deprecated `ignore_extra` and `allow_extra` Config fields in favor of `extra`, fix #352

* refaactored extra types to use a single enum

* slightly simplified

* added tests

* fixed most stuff

* docs and some simplifications

* better assert

* changed enum and fixed logic

* trying to capture deprecation warning

* make format

* fixing tests and moving exta logic to __new__

* set_extra tests

* fox benchmarks

* formatting

* updated history

* docs

* added a negative tests

* reverted format changes

* format

* matched casing

* renamed values

* more fixes

* forgot values change

* another one

* weird stuff

* linting issue

* Update pydantic/main.py

Co-Authored-By: liiight <4374581+liiight@users.noreply.github.com>
2019-02-04 13:15:07 +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
Hugo Duncan 3249330b80 Properly set Config in create_model (#320)
* Properly set Config in create_model

Set the Config attribute in create_model, so it is found by the
MetaModel.

* Black formatting fixes

* Remove uneeded validator logic

* Use single quotes

* Add return value to inherit_validators

* Refactor inherit_validators

* Add HISTORY.rst entry

* Address feedback

* Extend existing validator test cases and remove field aliasing

* Add test cases for validators inherted from parent

* Make test case names consistent with where validators are configured

* Add detail create_model validator inheritance tests
2018-12-07 20:27:42 +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 f0f9de5f96 improve docs on error handling (#198)
* improve docs on error handling

* change ValidationError signature

* cleanup

* rename _raw_errors > raw_errors

* improve _display_error_type_and_ctx
2018-06-11 13:06:50 +01:00
Nikita Grishko 4f4e22ef47 Error context and message (#183)
* POC of error context and message

* Move type errors to the `errors.py` module; Change errors interface a bit

* Rename `.as_dict()` to `.dict()`

* Fix `PydanticErrorMixin` constructor

* Rename `exceptions.py` to `error_wrappers.py`

* Do not include nullable `ctx`

* Fix tests

* Added `int_validator`; Added `IntegerError`

* Added `float_validator`; Added `FloatError`

* Get rid of `__mro__` in prior of `exc.code`

* Removed `min_number_size` and `max_number_size` from config (#174)

* Added `NumberMinSizeError` and `NumberMaxSizeError`

* Added `NoneIsNotAllowedError`

* Added `EnumError`

* Added `path_validator`; Added `PathError`

* Added `DictError`

* Added `ListError`

* Added `TupleError`

* Added `SetError`

* Added `datetime` related errors

* Added `bytes` and `str` related errors

* Added `SequenceError`

* Improved code coverage

* Display error context in string representation of validation error

* Redefine error message templates using config

* Review fixes

* Updated changelog
2018-05-31 14:35:38 +01:00
Nikita Grishko 31683f8dc4 Errors format (#179)
* Get rid of `track` in errors

* Move `display_as_type` func into utils module

* Get rid of error as `namedtuple`

* Renamed `Error.index` to `Error.loc`

* New way to get error type

* New way to get error message

* New errors format

* Renamed `flatten_errors` property to `flat_errors`

* `__slots__` for `Error` and `ValidationError`

* `loc` as `tuple`

* Tests

* Review fixes

* `flatten_errors` as generator
2018-05-23 14:50:04 +01:00
Samuel Colvin 3eec750640 allow custom get_field_config (#165)
* allow custom get_field_config, fix #159

* improving config inheritance
2018-05-10 12:12:37 +01:00
Samuel Colvin a8096959e2 check for invalid validators (#140)
* check for invalid validators

* documentation and history
2018-03-25 16:41:48 +01:00
Samuel Colvin 03838d9220 stop create_model modifying its base 2018-02-07 17:32:20 +00:00
Samuel Colvin 89201f08b0 add wildcard validators (#128)
* add wildcard validators

* update docs and history

* more tests

* history links
2018-02-06 19:32:30 +00:00
Samuel Colvin eeb5698e75 funky test with create_model 2018-02-06 17:01:55 +00:00
Samuel Colvin c18b2bc4fc rename config -> __config__ on a model 2018-02-06 14:39:38 +00:00
Samuel Colvin f9cf6b42f4 Create model method (#125)
* adding create_model method

* adding  method

* docs and tweaks

* prevent config and base together

* tweak docs
2018-02-06 14:29:56 +00:00