* 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>
* 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>
* 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
* 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>
* 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>
* 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>
* Change str_validator() return type to str
* Make pattern_validator() accept pre-compiled Pattern objects.
Resolves#1237.
* fix str_validator return type
Co-authored-by: Samuel Colvin <samcolvin@gmail.com>
* README change to make type annotations valid
* example fixed to have valid type annotations
* changes description
* Update README.md
explicit assignment for an optional field
Co-Authored-By: Samuel Colvin <samcolvin@gmail.com>
* Update docs/examples/index_main.py
explicit assignment for an optional field
Co-Authored-By: Samuel Colvin <samcolvin@gmail.com>
Co-authored-by: Samuel Colvin <samcolvin@gmail.com>
* Add right __init__ signature generation
* Add params overlay support for custom __init__, enhance tests
* Change fake_ini creation to solve AttributeError in cython
AttributeError: attribute '__code__' of 'cython_function_or_method' objects is not writable
Possible there's other attrs that cannot be set in cython, but can't check myself yet
* Cython compatibility, add __signature__, ignore non-identifiers fields
Moved tests to separate file
Moved __init__ creation to utils
* Remove # pragma: no cover
Co-Authored-By: Samuel Colvin <samcolvin@gmail.com>
* Fixed adding signature to doc, some compatibility fixes
* Changed None to tuple() for py3.8 compatibility
* Finally (hope so) fix issues with closure. Add new docstring each time
* coverage for UndefinedType
* Checking signature more simple and obvious way
* Changed doc caption to simple message, used Undefined, merge conflicts
* Compatibility with py3.6
* Add changes/ file
* Ah, that space... Reformatted and ready to go!
* Update pydantic/main.py
Co-Authored-By: Samuel Colvin <samcolvin@gmail.com>
* Update pydantic/main.py
Co-Authored-By: Samuel Colvin <samcolvin@gmail.com>
* Fix signature for properties declared as fields
* Sort imports
* Add comments
* Generate BaseModel signature instead of __init__ signature
* Fixed imports
* Minor improvements from review
* Add docs for model signature
* Delete unused imports
* Fix formatting in tests
* Remove inspect imports from top level
* Update docs/examples/models_signature.py
Co-Authored-By: Samuel Colvin <samcolvin@gmail.com>
* Add missing import
* Remove notes from doc
* change hypothesis-auto mention to hypothesis
* Use None as slice end instead of len()
* tweak generate_model_signature
* improve docs
* Revert af3dd4d, add fields to custom init only if var_kw declared
Co-authored-by: Samuel Colvin <samcolvin@gmail.com>
* Refactor ._iter() method:
Moved all keys-related stuff (include, exclude, etc.) to ._iter()
Removed redundant iteration through default values
Almost all arguments checks moved out of loops, so checks happen once
Fast yield from .__dict__ on plain .iter() (x10 boost)
Removed redundant set(dict.keys()) in ._calculate_keys()
* Moved back from nested generator checks to checks, optimized copy a bit
* Bump pytest-mock from 1.12.0 to 1.12.1 (#1018)
Bumps [pytest-mock](https://github.com/pytest-dev/pytest-mock) from 1.12.0 to 1.12.1.
- [Release notes](https://github.com/pytest-dev/pytest-mock/releases)
- [Changelog](https://github.com/pytest-dev/pytest-mock/blob/master/CHANGELOG.rst)
- [Commits](https://github.com/pytest-dev/pytest-mock/compare/v1.12.0...v1.12.1)
Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
* __str__ and __repr__ inheritance for models, fix#1022 (#1023)
* add testimonials section to docs with reference to python bytes podcast episode (#1025)
* add testimonials section with reference to python bytes podcast episode
* added description to changes directory
* Bump twine from 3.0.0 to 3.1.0 (#1029)
Bumps [twine](https://github.com/pypa/twine) from 3.0.0 to 3.1.0.
- [Release notes](https://github.com/pypa/twine/releases)
- [Changelog](https://github.com/pypa/twine/blob/master/docs/changelog.rst)
- [Commits](https://github.com/pypa/twine/compare/3.0.0...3.1.0)
Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
* Support typing.Literal in python 3.8 (#1027)
* Support typing.Literal in python 3.8
* Improve import pattern for Literal
* Update references to in docs
* Try to get build to pass
* Add support for mapping types as custom root (#958)
* Add support for mapping types as custom root
* Incorporate feedback
* Add changes
* Incorporate feedback
* Add docs and tests
* Fix linting issue
* Incorporate more feedback
* Add more specific match
* Add parse_as_type function (#934)
* Add parse_as_type function
* Add changes
* Incorporate feedback
* Add naming tests
* Fix double quotes
* Fix docs example
* Reorder parameters; add dataclass and mapping tests
* Rename parse_as_type to parse_obj, and add parse_file
* Incorporate feedback
* Incorporate feedback
* use custom root types
* Add better support for validator reuse (#941)
* Add better support for validator reuse
* Clean up classmethod unpacking
* Add changes
* Fix coverage check
* Make 3.8 compatible
* Update changes/940-dmontagu.md
Co-Authored-By: Samuel Colvin <s@muelcolvin.com>
* Make allow_reuse discoverable by adding to error message
* switch _check_validator_name to _prepare_validator
* Add changes file
* Delete unrelated files
* Add check that k in fields before using alias
Co-Authored-By: Samuel Colvin <samcolvin@gmail.com>
* Remove redundant call to __iter__
Co-Authored-By: Samuel Colvin <samcolvin@gmail.com>
* Use typing.AbstractSet
* Update pydantic/main.py
Co-Authored-By: Samuel Colvin <samcolvin@gmail.com>
Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
Co-authored-by: Samuel Colvin <samcolvin@gmail.com>
Co-authored-by: Colin Sullivan <csullivan@brandwatch.com>
Co-authored-by: David Montague <35119617+dmontagu@users.noreply.github.com>
* feat: add pydantic.color.Color as available type for Pydantic color fields
* chore: test for color
* chore: change md
* fix: assertion is incorrect
* fix: logic on _original assignment
* fix: value is set to value._original in the isinstance conditional
fix: remove ._original conditional (logic is set earlier in the method)
fix: removed pydantic.color.Color line from errorstring
* chore: revert error message adjust
* chore: grammaer ;)
* starting validation_decorator
* correct skip_pre_38
* fix coverage and type hints
* mypy tests and move to class based decorator
* 3.6 fix, prevent duplicate github actions
* correct py 3.6 check
* better errors
* cleaner field names for args and kwargs
* add change and comments
* starting docs
* back to 3.7 for docs
* docs
* bump
* add async example and fix print indents
* allow type annotations as strings
* python 3.8 in docs
* fix alias priority so alias_generators don't take priority
* improve test names
* remove debugs
* Apply suggestions from code review
* more tests and allow custom alias_priority on fields
* precedence tests and docs
* tweaks and add change
* suggestions
* allow use of a `.env`-style files in BaseSettings (#607)
* address various issues with initial implementation
- allow specifying `_env_file` kwarg in instantiation
* overrides any `env_file` specified in the `Config` class
- cast `os.environ` as a dict for better consistenty of behavior
- `env_path` should be a `Path` type
- replace `with open()` with `read_text`
- use regex for parsing the dotenv files and throw error on invalid line
- factor out `read_env_file` into separate file for easier testing
* move back into a single file; revert typing changes; use regex better
* pass `_env_file` argument around instead of setting a class attribute
* add dotenv docs
* add dotenv tests
* Add changes file
* Flesh out the docs a bit
* Apply suggestions from @samuelcolvin's code review
Co-Authored-By: Samuel Colvin <samcolvin@gmail.com>
* wrap docs
* add not about priority
* fix tests and imports
* fix tests
* switch to python-dotenv
* cleanup, test example
* more docs tweaks
* typo
* fix tests for dotenv
Co-authored-by: Samuel Colvin <samcolvin@gmail.com>
* ✨ Add support for generics with __get_validators__
* ✅ Add tests for Generics with __get_validators__
* 📝 Add change note
* ✨ Add support for Generic fields with validation of sub-types
* 📝 Add docs for arbitrary generic types
* ✅ Add tests for generic sub-type validation
* 📝 Update change note. Generic support is not so "basic" now
* 📝 Update docs with code review
* ♻️ Update fields module with code review changes
* ✅ Update tests from code review
* 📝 Update example for generics, try to simplify and explain better
* tweak docs example
Co-authored-by: Samuel Colvin <samcolvin@gmail.com>
* ✨ Implement support for infinite generators with Iterable
* ✅ Add tests for infinite generators
* 🎨 Fix format
* 📝 Add docs for infinite generators
* 📝 Add changes file
* ✨ Store sub_field with original type parameter to allow custom validation
* 📝 Add example for validating first value in infinite generators
* 🔥 Remove unused import in example
* ✅ Add test for infinite generator with first-value validation
* ♻️ Update fields with code review
* 📝 Update example from code review
* 📝 Update docs and format from code review
* Pass model_class to schema_extra staticmethod
Resolves#1122
* Add changelog
* Apply suggestions from code review
Co-Authored-By: Samuel Colvin <samcolvin@gmail.com>
* Fix import after rebase
* Fix test bug
* Use TypeError instead of assert as per review
* Rename var so declaration fits one one line
* tiny tweaks
Co-authored-by: Samuel Colvin <samcolvin@gmail.com>
* Added optional for root_validator to be skipped if values validation fails
* cleaner usage of skip_on_failure
* skip_on_failure: documentation update