Commit Graph

22 Commits

Author SHA1 Message Date
Samuel Colvin 594effa279 Switching to pydantic_core (#4516)
* working on core schema generation

* adapting main.py

* getting tests to run

* fix tests

* disable pyright, fix mypy

* moving to class-based model generation

* working on validators

* change how models are created

* start fixing test_main.py

* fixing mypy

* SelfType

* recursive models working, more tests fixed

* fix tests on <3.10

* get docs build to pass

* starting to cleanup types.py

* starting works on custom types

* working on using annotated-types

* using annoated types for constraints

* lots of cleanup, fixing network tests

* network tests passing 🎉

* working on types

* working on types and cleanup

* fixing UUID type, restructing again

* more types and newer pydantic-core

* working on Iterable

* more test_types tests

* support newer pydantic-core, fixing more test_types.py

* working through more test_types.py

* test_types.py at last passing locally 🎉

* fixing more tests in test_types.py

* fix datetime_parse tests and linting

* get tests running again, rename to test_datetime.py

* renaming internal modules

* working through mypy errors

* fixing mypy

* refactoring _generate_schema.py

* test_main.py passing

* uprev deps

* fix conftest and linting?

* importing Annotated

* ltining

* import Annotated from typing_extensions

* fixing 3.7 compatibility

* fixing tests on 3.9

* fix linting

* fixing SecretField and 3.9 tests

* customising get_type_hints

* ignore warnings on 3.11

* spliting repr out of utils

* removing unused bits of _repr, fix tests for 3.7

* more cleanup, removing many type aliases

* clean up repr

* support namedtuples and typeddicts

* test is_union

* removing errors, uprev pydantic-core

* fix tests on 3.8

* fixing private attributes and model_post_init

* renaming and cleanup

* remove unnecessary PydanticMetadata inheritance

* fixing forward refs and mypy tests

* fix signatures, change how xfail works

* revert mypy tests to 3.7 syntax

* correct model title

* try to fix tests

* fixing ClassVar forward refs

* uprev pydantic-core, new error format

* add "force" argument to model_rebuild

* Apply suggestions from code review

Suggestions from @tiangolo and @hramezani 🙏

Co-authored-by: Hasan Ramezani <hasan.r67@gmail.com>
Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>

* more suggestions from @tiangolo

* extra -> json_schema_extra on Field

Co-authored-by: Hasan Ramezani <hasan.r67@gmail.com>
Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
2022-11-02 12:01:17 +00:00
Samuel Colvin 0244b06be5 Warn and ignore __slots__ argument to create_model (#4432)
* add test for create_model with slots

* add test for create_model with slots

* add warning and change description

* fix flakey none tests on 3.8.10

* avoid flakey coverage changes
2022-08-24 20:13:07 +01:00
Talley Lambert beb3e4c8f1 Fix duplicate calls to __set_name__ for non-private attributes in BaseModel.__new__ (#4410)
* fix: double call for public attrs, extend test

* add changes

* remove change file, update 4407 file
2022-08-22 11:16:53 +00:00
Talley Lambert d501c39f2b Fix PEP487 __set_name__ protocol in BaseModel (#4407)
* fix: fix __set_name__ protocol in BaseModel

* undo changes

* add comment

* fix lint

* fix lint

* add change file

* remove mock, move imports
2022-08-21 13:53:26 +00:00
chenyijian 02a2a8b5c0 create_model support generics model (#3946)
* create_model support generics model

* fix change.

Co-authored-by: chenyijian <chenyijian@mycapital.net>
Co-authored-by: Samuel Colvin <samcolvin@gmail.com>
2022-08-11 10:34:24 +00:00
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