* added config var warn_on_undefined_types
raises a UserWarning if model not fully defined and will need rebuild
* black formatting
* use | instead of Optional[]
* suppress undefined types warning in existing tests
* ran pre-commit to fix linting
* changed to use Optional since | failing in CI
* changes following initial code review
* added some preliminary documentation
* fix linting
* fixed linting
* fixed linting
* assert model partially built when suppressing warn
* moved check for ForwardRef into existing for loop
* change assertion to dict instead of json
* cleanup of undefined_types_warning tests and docs
* Update docs/examples/types_undefined_warning.py
* Update docs/examples/types_undefined_warning.py
* fix EOL (trim trailing whitespace) lint error
Co-authored-by: Samuel Colvin <s@muelcolvin.com>
Hello
BaseModel is an import from pydantic.
Using that same name for the Base from sqlachemy can be misleading, and not aligned to the other examples.
I therefore suggest to use the same naming that the other example.
Pierre
* 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>
* Fix#1458 - Allow for custom parsing of environment variables via env_parse
* Add docs for env_parse usage
* Add changes file for #3977
* fixup: remove stray print statement
* Revert env_parse property on field
* Add parse_env_var classmethod in nested Config
* Update documentation for parse_env_var
* Update changes file.
* fixup: linting in example
* Rebase and remove quotes around imported example
* fix example
* my suggestions
* remove unnecessary Field(env_parse=_parse_custom_dict)
Co-authored-by: Samuel Colvin <s@muelcolvin.com>
* Fix `AnyUrl.build` doesn't do percent encoding (#3061)
please review
* Use `urllib.parse` instead of custom implementation for percent encoding
* Make `quote_plus` a `stricturl` option
* Add docs for `stricturl(quote_plus=True)`
* Better changes message for #3061
Co-authored-by: Samuel Colvin <samcolvin@gmail.com>
* Fix precent encoding version note to V1.10
Co-authored-by: Samuel Colvin <samcolvin@gmail.com>
* Fix `Building URLs` snippit markdown
Co-authored-by: Samuel Colvin <samcolvin@gmail.com>
* Fix formatting for `docs/examples/types_url_building.py`
* fix docs
Co-authored-by: Samuel Colvin <samcolvin@gmail.com>
Co-authored-by: Samuel Colvin <s@muelcolvin.com>
* Generate docs exampels for Python 3.10 and above
Code quality is not great and main intent here is to show the result.
* Fix docs build on 3.9
* Build docs on 3.10
* What's Python 3.1?
* Create temp dir if not exists
* Refactor and improve imlementetion
* Keep runtime typing in examples
* Revert unrelated formatting changes
* Add changes file
* Allow specifying requirements in examples
* Pin autoflake and pyupgrade
* Add docs/build to Makefile lint/format/mypy
* ignore_missing_imports for ansi2html and devtools
* Add .tmp-projections to .gitignore
* Remove dont-upgrade now when Pattern is supported
* Update postponed evaluation examples
Co-authored-by: Samuel Colvin <s@muelcolvin.com>
* Change path in validation_decorator_types example to a relative path
* make the example a little clearer
Co-authored-by: Samuel Colvin <s@muelcolvin.com>
* Add .venv/ to .gitignore
* Allow typecheckers to infer Json inner type
* Fix and improve mypy tests
* Add type tests
* Add Json[Any] case to schema test
* Update example in docs
* Add changes file
* Use <3.9 compatible annotations for tests
* feat: add to upper function for strings and bytes
* docs(changes): add message for change
* fix: add constr upper on types
* fix: add constr upper on types
* feat: add examples and doc usage
* test: add test to upper for types
* chore: apply suggestions from code review
Co-authored-by: Hasan Ramezani <hasan.r67@gmail.com>
* chore(docs): reorder `anystr_upper` to under `anystr_lower`
* fix(test): adjust parametrizes to constrained bytes upper
* refactor: use pytest parametrize for unify test constrained str upper
* refactor: use pytest parametrize for unify test constrained str lower
* refactor(test): use pytest parametrize for unify test any str upper
* refactor(test): use pytest parametrize for unify test any str lower
* refactor(test): use pytest parametrize for unify test constrained bytes lower
* refactor(test): use pytest parametrize for unify test any str strip whitespace
* refactor(test): change test signatures to improve readability
Co-authored-by: Hasan Ramezani <hasan.r67@gmail.com>
* add support for alias handling in validate_arguments
* add test for alias handling in validate_arguments
* add documentation on alias support for decorator
* bug fixed in the validate_argumen decorator documentation
* add changes README
* change in the documentation due to a drafting error
* Update changes/3019-MAD-py.md
Co-authored-by: Eric Jolibois <em.jolibois@gmail.com>
* more challenging tests
* run the format checker
* integration of empty string as alias
Co-authored-by: Eric Jolibois <em.jolibois@gmail.com>
Co-authored-by: Samuel Colvin <s@muelcolvin.com>
* fix: handle basemodel fallback for custom encoders
* put back old behaviour and add to_dict
* typo
Co-authored-by: Christian Bundy <christianbundy@fraction.io>
Co-authored-by: Christian Bundy <christianbundy@fraction.io>
* Add RabbitmqDsn
Will update once finished - haven't looked at the CONTRIB yet. Want to test locally to see if it works.
* added tests; added to docs
* added changes
* fixed import in networks.py
* fixed linting issues; fixed __init__.py import issue
* sorted imports
* added trailing comma on imports
* Merge master
* Change class name from RabbitmqDsn to RabbitMqDsn
* Format code
* Rename change file and prettify content
* Fix RabbitMQ name on documentation
* Add a trivial test
* Address Samuel and Nuno's comments
* Refactor AMQP tests according to Redis tests style
* Update docs/examples/settings_main.py
* cleanup
Co-authored-by: Thomas <thomas@9bitbyte.com>
Co-authored-by: Thomas Crha <tom.crha@dragonflytechnologies.com>
Co-authored-by: Samuel Colvin <s@muelcolvin.com>
* Try to evaluate forward refs after model created
* Upadate docs and remove code duplication
* Update changes/2588-uriyyo.md
Co-authored-by: Eric Jolibois <em.jolibois@gmail.com>
* Update docs/usage/postponed_annotations.md
Co-authored-by: Eric Jolibois <em.jolibois@gmail.com>
* Remove unused import
Co-authored-by: Eric Jolibois <em.jolibois@gmail.com>
* Add GetterDict example
* Update docs/usage/models.md
Co-authored-by: Samuel Colvin <samcolvin@gmail.com>
Co-authored-by: Samuel Colvin <samcolvin@gmail.com>
* Add exclude/include as field parameters
- Add "exclude" / "include" as a field parameter so that it can be
configured using model config (or fields) instead of purely at
`.dict` / `.json` export time.
- Unify merging logic of advanced include/exclude fields
- Add tests for merging logic and field/config exclude/include params
- Closes#660
* Precompute include/exclude fields for class
* Increase test coverage
* Remove (now) redundant type checks in Model._iter: New
exclusion/inclusion algorithms guarantee that no sets are passed further down.
* Add docs for advanced field level exclude/include settings
* Minimal optimization for simple exclude/include export
Running benchmarks this vs. master is at:
this: pydantic best=33.225μs/iter avg=33.940μs/iter stdev=1.120μs/iter version=1.7.3
master: pydantic best=32.901μs/iter avg=33.276μs/iter stdev=0.242μs/iter version=1.7.3
* Apply review comments on exclude/enclude field arguments
* Fix/simplify type annotations
* Allow both ``True`` and ``Ellipsis`` to be used to indicate full field
exclusion
* Reenable hypothesis plugin (removed by mistake)
* Update advanced include/include docs to use ``True`` instead of ``...``
* Move field info exclude/include updates into FieldInfo class
This way, the model field object does not need to concern itself with
dealing with field into specific fields.
(Same was done for alias in a previous commit).
* remove double back tick in markdown.
Co-authored-by: Samuel Colvin <samcolvin@gmail.com>
* 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`
* add support for class kwargs config
* reformat tests
* add changes file and docs
* fix linting in 'inherit_config'
* tweak docs
Co-authored-by: Samuel Colvin <s@muelcolvin.com>
* Infer root type from Annotated
* Extract Field from Annotated
* Add changelog
* Extend existing get_args/get_origin
* Fix Annotated on py3.6 without typing-extensions
* Handle Ellipsis default
* Fix field reuse after FieldInfo.default mutation
* Fix ci
* fix(decorator): detect when a duplicate argument is passed in
Currently, it is possible to override a positional argument with a keyword
argument using the decorator.
In native python, this raises a TypeError.
Detect this usecase, to prevent keywords overriding positional parameters.
Closes: https://github.com/samuelcolvin/pydantic/issues/2249
* add changelog entry
* fix docs example to not override positional argument
Co-authored-by: Samuel Colvin <s@muelcolvin.com>
* feat: add support for `NamedTuple` and `TypedDict` types
* support `total=False`
* tests: fix ci with python < 3.8 without typing-extensions
* chore: improve mypy
* chore: @samuelcolvin remarks
* refactor: move tests in dedicated file
* docs: add annotated types section with examples
* feat: support properly required and optional fields
* chore(deps-dev): bump typing_extensions
* docs: add a note for `typing_extensions`
* chore: update message to be more accurate
* feat: pass down config to created models
* feat: add util methods to create model from TypedDict or NamedTuple
* refactor: rename into typeddict and namedtuple
* test: add utils tests
* chore: fix lint
* chore: improve test
* refactor: rename utils to match the rest
* chore: update change
* docs: add section for create_model_from_{namedtuple,typeddict}
* refactor: rename typed_dict/named_tuple
* feat: support schema with TypedDict
* feat: support schema for NamedTuple
* feat: add json support for NamedTuple
* chore: rewording
* refactor: use parse_obj
* fix: add check for max items in tuple
* docs: separate typing.NamedTuple and collections.namedtuple
* feat: avoid reconstructing models used as fields of another model on validation
closes#265closes#1837
* docs: add section to change config
* change default value to avoid breaking change
* refactor: only suggest custom BaseModel approach
* added anystr_lower field to config
* updated docs with any anystr_lower config property
* updated changes folder with markdown describing new change
* added anystr to _validators list under bytes type
* added unit tests for anystr_lower config
* Update pydantic/validators.py
Fix wrong method used in cosntr_lower
Co-authored-by: Eric Jolibois <em.jolibois@gmail.com>
* added lower_str to conbytes and constr functions
* Update changes/2134-tayoogunbiyi.md
Co-authored-by: Samuel Colvin <samcolvin@gmail.com>
* renamed conbytes & constr paramater name
* updated change markdown
* added docs for args to constr and conbytes
* added examples to showing to_lower functionality in conbytes & constr
* added better description for curtail_length
* removed unessary whitespace, added default and types in docs
* Update changes/2134-tayoogunbiyi.md
Co-authored-by: Eric Jolibois <em.jolibois@gmail.com>
* added single whitespace to arguments list under constr & conbytes
Co-authored-by: Eric Jolibois <em.jolibois@gmail.com>
Co-authored-by: Samuel Colvin <samcolvin@gmail.com>
Co-authored-by: Samuel Colvin <s@muelcolvin.com>
* feat: Add the ability to add extra settings sources
* doc: Document "customise settings sources" feature
* tests: Add missing test and add change file
* Update changes/2107-kozlek.md
Co-authored-by: Eric Jolibois <em.jolibois@gmail.com>
* improve docs for settings customise_sources
* fix docs building
* fix test :-(
Co-authored-by: Thomas Berdy <thomas.berdy@outlook.com>
Co-authored-by: Eric Jolibois <em.jolibois@gmail.com>
Co-authored-by: Samuel Colvin <s@muelcolvin.com>
* Added StrictBytes type
* updated tests for StrictBytes, updated relevant sections in documentation for StrictBytes and ConstrainedBytes
* added changelog
* chore: typo in change
Co-authored-by: Eric Jolibois <em.jolibois@gmail.com>