* 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>
* feat(field): add Enum type support
closes#1735
* test: add extra cases and rename to be more explicit
* refactor: rename enum_validator
* feat: add Enum and IntEnum types support
* docs: add new types
* chore: update change message
* feat: use partially get_origin and get_args from typing
Rework of d86a184072655d93652d6ea941421005f34de962 by @hmvp
We cannot directly use `typing.get_origin` and `typing.get_args` for
our custom types for which args and origin are wrong by default.
But at least we now have a unified behaviour, which can be improved
in the near future
* feat: add fallback in `get_args` for generics in python 3.9
* feat: add new `_evaluate` for python 3.9
In python 3.9, `typing._evaluate` has a new required
positional argument `recursive_guard`
* chore: add pragma no cover for python 3.9 fallbacks
* chore: add change file
* chore: add comments
* feat(ci): add python 3.9 support
* fix: mypy assumption is wrong
* refactor(schema): put schema data from fieldinfo in dedicated function
* feat(schema): support custom title, description and default for enums
closes#1748
* refactor: replace $ref by allOf + $ref to be supported by doc generation tools
* fix: do not set title by default for enums
* refactor: make code more explicit
* fix: run linter
* fix: forward ref with nested models and optional fields
PR #1712 introduced a regression for forward refs in `ModelField.prepare`
as it would not return early for forward refs anymore.
Optional fields would hence have `required` set to `True`.
closes#1736
* test: skip python 3.6 as __future__.annotations is not defined
* fix: validate nested models with `default_factory`
PR #1504 introduced a regression by bypassing `populate_validators()`,
which would skip the validation of children in nested models
with `default_factory`
closes#1710
* test: add example of nested models parsing with `default_factory`
closes#1717
* add testcase from #1722
* bodge for benchmarks
Co-authored-by: Samuel Colvin <s@muelcolvin.com>
* Fix nested all include exclude
* Ensure original exclude value is not modified
This commit also fixes some weird cases in the recursive
`update_normalized_all` call and Ellipsis values.
* Add docstring, parametrize tests
* Fix master
* Fix master 2 (#1694)
* test: add regression test with wrong type default
* fix: remove always on conlist and conset
* fix: use utf8 as default encoding on all OS
* conset invalid defualt test
* add change
Co-authored-by: PrettyWood <em.jolibois@gmail.com>
* 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>
* 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
* 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
* 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>
* 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>
* 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.
* 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>
* 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
* 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>