Commit Graph

342 Commits

Author SHA1 Message Date
Shahriyar Rzayev 7108652d0b Renamed schema variable name to schema_ as there is a schema function defined (#2724)
* Renamed schema variable name to schema_ as there is a schema function already defined

* Same approach in enum_process_schema()

* added changes file

* Update changes/2724-shahriyarr.md

Co-authored-by: Samuel Colvin <samcolvin@gmail.com>

* last shadow rename

Co-authored-by: Samuel Colvin <samcolvin@gmail.com>
Co-authored-by: PrettyWood <em.jolibois@gmail.com>
2021-09-04 04:35:54 +02:00
Yurii Karabas 0d1ed534ac Fix mypy plugin issue with self field (#2743)
* Fix mypy issue with self field

* Add docs
2021-09-04 04:15:49 +02:00
Samuel Colvin 8c6b9ca285 prevent StrictStr allowing Enum values (#2729)
* prevent StrictStr allowing Enum values

* add change

* bump
2021-09-04 04:13:32 +02:00
Eric Jolibois f9c65c5b88 fix: add/fix BaseConfig type annotations (#2720) 2021-09-04 04:13:20 +02:00
Eric Jolibois bd61f1b6ee fix: stop calling parent class root_validator if overridden (#2670)
* fix: stop calling parent class `root_validator` if overridden

* refactor: better name, default and typing
2021-09-04 03:55:11 +02:00
maximberg 93aed51183 Advanced use of generic fields in schema generation (#2375)
* Added schema generation for Generic fields with tests.
Fixed test_assert_raises_validation_error.

* Added schema generation for Generic fields with tests.
Fixed test_assert_raises_validation_error.

* tested on python 3.6, 3.7, 3.8, 3.9

* tested on python 3.6, 3.7, 3.8, 3.9

* restore formatting

* fix mistakes

* formatting

* formatting

* formatting

* fixed coverage

* changes file

* changes file

* remove redundant len

* Update pydantic/schema.py

Co-authored-by: Maz Jaleel <mazjaleel@gmail.com>

* Generic fields with params

* Generic fields with params

* Fix my previous test

* formatting

* merging with nested models-generics

* formatting

* formatting

* rewording

Co-authored-by: Maxim Berg <berg@petrostyle.com>
Co-authored-by: Maz Jaleel <mazjaleel@gmail.com>
Co-authored-by: PrettyWood <em.jolibois@gmail.com>
2021-09-04 02:58:43 +02:00
Vasilis Gerakaris 8417b3bb5c add FileUrl type for file:// schemes, add host_required parameter (#2434)
* add `FileUrl` type for `file://` schemes

Also add a `host_required` parameter, True by default,
False in `FileUrl` and `RedisDsn`.

* chore: useless extra in assert statement

Co-authored-by: PrettyWood <em.jolibois@gmail.com>
2021-09-04 02:10:25 +02:00
Mikhail Sitnikov 65fc336cf3 added KafkaDsn to networks.py and add default ports for HttpUrl (#2447)
* added KafkaDsn to network

* added short description to chandes folder

* added default non-displayable ports to HttpUrl model

* added info to changes folder

* fix: support non default ports in HttpUrl

* fix pr issues

* remove noqa

* add more typing by @PrettyWood

* add default http and https ports to `HttpUrl` model

* fix mypy

* chore: do not add implementation details

Co-authored-by: PrettyWood <em.jolibois@gmail.com>
2021-09-04 01:46:55 +02:00
Fernando ike 1a9f59dc1e Support postgresql+asyncpg schema for PostgresDsn (#2567)
* Added suport to postgresql async driver

* Added postgres+asyncpg in the doc.

* Added changes file

* Added postgresql+pg8000 schema

* ran make format

* Update docs/usage/types.md

Co-authored-by: Stephen Brown II <Stephen.Brown2@gmail.com>

* Changed from schema to scheme

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

* fixed typo scheme

* fixed merge schema

* changed to one line description

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

* added others DBAPI dialects.

* Added two # by PrettyWood

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

* fix typo by PrettyWood

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

* Fixed typo by PrettyWood

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

* added postgresql+psycopg2 in changes dir

* Fixed typo by @samuelcolvin

Co-authored-by: Samuel Colvin <samcolvin@gmail.com>

* docs: fix typo

* chore: sort alphabetically

Co-authored-by: Fernando Ike <fernando.ike@maburix.com>
Co-authored-by: Stephen Brown II <Stephen.Brown2@gmail.com>
Co-authored-by: Eric Jolibois <em.jolibois@gmail.com>
Co-authored-by: Samuel Colvin <samcolvin@gmail.com>
2021-09-04 01:19:54 +02:00
Nuno André 5549e8d379 Fix recursive ORM parsing error (#2718)
The _ORM mode_ doesn't parse dictionaries if it's not explicitly called.
2021-09-04 00:47:11 +02:00
Davis Kirkendall 3d287594e0 Allow collections.abc.Callable to be used as type in python 3.9 (#2519)
* Allow collections.abc.Callable to be used as type in python 3.9

* Add is_none_type as function to check none types by identity

* Modify `typing.is_none_type` to work in python 3.6 and 3.7

* Add tests for none types in typing.py

* Apply review comments on #2519
* Add different implementations depending on python version
* Add tests for is_none_type

* Add change entry

* Fix field info repr

* Remove unneeded try/except for python < 3.8

* Add comment explaining alternative is_none_type implementation

* fix: typo

Co-authored-by: PrettyWood <em.jolibois@gmail.com>
2021-09-04 00:25:28 +02:00
Eric Jolibois 4a54f393ad Add python 3.10 support (#2885)
* refactor: extra `BaseConfig` and `Extra` in dedicated `config` module

* refactor: clean useless `#noqa: F401`

* refactor: clean useless `#noqa: F811`

* refactor: replace enum check

Error with 3.10
> DeprecationWarning: accessing one member from another is not supported

* refactor: avoid using `distutils` directly

error with python 3.10
> DeprecationWarning: The distutils package is deprecated and slated
> for removal in Python 3.12.
> Use setuptools or check PEP 632 for potential alternatives

* fix: `__annotations__` always exists

* fix: origin of `typing.Hashable` is not `None`

* ci: add run with 3.10.0b2

* docs: add 3.10

* feat: support `|` union operator properly

`|` operator has origin `types.Union` (and not `typing.Union`)

* fix: enum repr is different with 3.10+

* fix: error message changed a bit

change from basic `__init__` to `test_hashable_required.<locals>.MyDataclass.__init__()` (with `__qualname__`)

* fix:  always exists and is not inherited anymore

* fix: avoid calling `asyncio.get_event_loop` directly

With python 3.10, calling it results in
> DeprecationWarning: There is no current event loop

* fix(ci): do not run 3.10 on linux for now

For now it can not be compiled.
Let's just skip the check on linux for now instead of tuning the CI pipeline

* fix(ci): ignore DeprecationWarning raised by `mypy` on windows

* docs: add change file
2021-07-19 14:23:07 +01:00
Marcelo Trylesinski a4cb4ee3bc feat: add PastDate and FutureDate types (#2425)
* feat: add PastDate and FutureDate types

* add changes file

* add tests

* fix: json schema

* fix: black format

* less code duplicated

* add dates on success.py

* fix past and future dates

* ♻️ Apply Samuel's comments

* 🚨 Satisfy flake8

* 🔥 Remove _DateValueError

* test: add last explicit case

Co-authored-by: PrettyWood <em.jolibois@gmail.com>
2021-06-04 23:30:25 +02:00
Peter Roelants 2e2edf4f11 Allow custom CFLAGS and update documentation on reducing size. (#2517)
Squashed commit Co-authored-by: Eric Jolibois <em.jolibois@gmail.com>
2021-06-04 21:42:49 +02:00
Ratul Maharaj aca18a9863 Added Talk Python Episode 313 to docs (#2712)
* Added Talk Python Episode 313

* Added changes file

* Update docs/index.md

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

* Fixed typo in Michael's name

Co-authored-by: Eric Jolibois <em.jolibois@gmail.com>
2021-06-04 19:41:01 +02:00
Nuno André b718e8e626 Add GetterDict example (#2463)
* Add GetterDict example

* Update docs/usage/models.md

Co-authored-by: Samuel Colvin <samcolvin@gmail.com>

Co-authored-by: Samuel Colvin <samcolvin@gmail.com>
2021-05-12 15:25:17 +01:00
Samuel Colvin 111ee2f5c9 V1.8.2 history (#2783)
* add change log for v1.8.2

* fix warning

* v1.6.2 and v1.7.4 to history
2021-05-11 21:28:16 +01:00
Samuel Colvin 7e83fdd256 Merge pull request from GHSA-5jqp-qgf6-3pvh
* fix infinite loop in datetime parsing

* add change description

* switch to set a max datetime number
2021-05-11 18:08:48 +01:00
Eric Jolibois a6154514c1 fix(schema): namedtuple with default (#2711)
Co-authored-by: Samuel Colvin <s@muelcolvin.com>
2021-05-11 15:13:54 +01:00
layday 0bfc930274 Allow passing json_encoders in class kwargs (#2523)
* Test that `json_encoders` are respected from class kwargs

* Allow passing `json_encoders` in class kwargs

Fixes #2521.
2021-05-11 15:03:51 +01:00
Frank Epperlein 362f4a5163 add repr parameter to hide a field from repr() (#2593)
* add repr parameter to hide a field from repr()

* fix styling issues

… found by flake8.

* fix type annotation issues

* correctly name changes file

* test hiding default values from repr() of a Field

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

Co-authored-by: Eric Jolibois <em.jolibois@gmail.com>
2021-05-09 14:16:52 +01:00
Eric Jolibois 0b3c5631bd fix: generate a valid name in schema for Enum classes (#2582)
* fix: generate a valid name in schema for `Enum` classes

* test: add schema with generic enum

* (erase me): just to check fastapi tests

* Revert "(erase me): just to check fastapi tests"

This reverts commit f334c4b575d413639d26c17c2c36d30333afcf7c.

* fix linting 😴

Co-authored-by: Samuel Colvin <s@muelcolvin.com>
2021-05-09 14:11:48 +01:00
Pax 68784f63c0 fix: provide __version__ attribute (#2573)
* fix: provide __version__ attribute

Pyinstaller is giving an error packaging a script that uses pydantic, "AttributeError: Module 'pydantic' has no attribute '__version__'"

See Issue #2572

* chore: add md file in changes folder

* test: __version__ attribute of pydantic module
2021-05-09 13:44:55 +01:00
Eric Jolibois 31c4efb7f0 fix: remove side effect of default_factory to always run it only once (#2566) 2021-05-09 13:35:15 +01:00
Davis Kirkendall e3b98a1db4 Support user defined generic field types in generic models. (#2554)
Work on #2465 (see comments)

Co-authored-by: Samuel Colvin <s@muelcolvin.com>
2021-05-09 13:11:31 +01:00
Eric Jolibois 4753901151 fix(schema): JSON schema generation with a Literal of an enum member (#2536)
Co-authored-by: Samuel Colvin <s@muelcolvin.com>
2021-05-09 12:20:54 +01:00
Yurii Karabas 0a5f0fae7a Fix issue with config decl at class level (#2532)
* Fix issue with config decl at class level

* Add changes

* Update pydantic/main.py

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

* Update changes

Co-authored-by: Eric Jolibois <em.jolibois@gmail.com>
2021-05-09 12:05:48 +01:00
Christopher Evans 9cc6d44682 Allow for generation of a constrained decimal with decimal_places argument for hypothesis plugin (#2524)
* Add functionality to create a constrained decimal strategy when decimal_place argument is provided

* adding readme

* edit readme

* adding back confloattmul test

* Update changes/2524-cwe5590.md

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

Co-authored-by: Eric Jolibois <em.jolibois@gmail.com>
2021-05-09 11:57:14 +01:00
Søren Bjerregaard Vrist 08fc8302cf Add lookahead for ip check in AnyUrl (#2512) 2021-05-09 10:49:19 +01:00
Eric Jolibois 9cc19e9a8e fix: support arbitrary types with custom __eq__ (#2502) 2021-05-09 10:44:53 +01:00
Koudai Aono 07908b3846 Add "strict" argument to "conbytes" (#2490)
* Add "strict" argument to "conbytes"

* Add unittest

* Update changes/2489-koxudaxi.md

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

Co-authored-by: Eric Jolibois <em.jolibois@gmail.com>
2021-05-09 10:27:29 +01:00
Alexandre Gerona 9f654a1fb2 fix(encoder): serialize NameEmail to str (#2479) 2021-05-09 10:26:02 +01:00
krisaoe 42395056e1 Fix(docs): remove colon to separate unrelated clauses (#2733)
* Fix(docs): remove colon to separate unrelated clauses 

The colon at the end of the line "The fields which were supplied when user was initialised:" suggests that the code following it is related.
Changed it to a period.

* Include change summary readme.
2021-05-03 17:46:37 +01:00
Davis Kirkendall db697cc799 Add exclude as field parameter (#2231)
* 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>
2021-05-01 16:45:37 +01:00
Samuel Colvin 908257914c docs preview and coverage using smokeshow (#2580)
* docs preview using smokeshow

* switch to using smokeshow for coverage

* fix macos and windows builds

* correct coverage prep.

* tweak coverage build logic

* print more coverage info

* mess with coverage setup, set config [PATHS]

* updating badges

* add context to coverage reports

* adding smokeshow status context
2021-03-27 18:36:52 +00:00
Samuel Colvin 619ff261c9 prepare for v1.8.1 2021-03-03 17:03:59 +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 3f84d1405e fix: validation with a BaseModel field and a custom root type (#2451) 2021-03-03 10:47:58 +00:00
Eric Jolibois ab691142b5 fix: avoid RecursionError when using some types like Enum or Literal with generic models (#2438)
* fix: support properly `Enum` when combined with generic models

* whitelist iterables

* update change description

* add test for Literal

Co-authored-by: Samuel Colvin <s@muelcolvin.com>
2021-03-03 09:25:23 +00:00
Tobi Lipede 429b439830 Allow for generation of a constrained float with multiple_of argument for hypothesis plugin (#2442)
* added method to generate a constrained float with multiple_of argument

* removed HealthCheck.filter_too_much

* Added change file

* fixes for case when min/max aren't provided; adding an extra test for float gt/lt with multiple of
2021-03-02 18:56:45 +00:00
Eric Jolibois a74232e101 fix: variable length tuples of compound types (#2421) 2021-03-02 12:09:31 +00:00
Eric Jolibois 37c37fd55e fix(mypy): fix custom Path and UUID related types (#2420)
* add tests that should pass

But we have those errors

226: error: Item "str" of "Union[UUID, str]" has no attribute "hex"  [union-attr]
227: error: Item "str" of "Union[UUID, str]" has no attribute "hex"  [union-attr]
228: error: Item "str" of "Union[Path, str]" has no attribute "absolute"  [union-attr]
229: error: Item "str" of "Union[Path, str]" has no attribute "absolute"  [union-attr]
230: error: Item "str" of "Union[Path, str]" has no attribute "absolute"  [union-attr]
231: error: Item "str" of "Union[Path, str]" has no attribute "absolute"  [union-attr]

* fix: right types should be valid

* remove new useless `type: ignore`

* docs: add change file
2021-03-02 12:07:07 +00:00
Eric Jolibois b2d3f333f0 refactor: set Pattern encoder in ENCODERS_BY_TYPE (#2444)
* refactor: set `Pattern` encoder in `ENCODERS_BY_TYPE`

* docs: add change file
2021-03-02 12:05:57 +00:00
Eric Jolibois f9fe4aa086 fix: do not overwrite declared hash in subclasses of a model (#2423) 2021-02-27 15:42:53 +00:00
Samuel Colvin aff4a41f9d preparing for v1.8 (#2414)
* preparing for v1.8 🎉 🚀

* change description for #2415

* tweak change descriptions

* fix nested lists in docs

* remove items in 1.7.3 from 1.8
2021-02-26 16:30:08 +00:00
xppt 8f0980e982 fix: prevent RecursionError while using recursive GenericModels (#2338)
Co-authored-by: Samuel Colvin <samcolvin@gmail.com>

Co-authored-by: Samuel Colvin <samcolvin@gmail.com>
2021-02-26 10:30:12 +00:00
Eric Jolibois 3ec35590f1 Support Field in dataclass + 'metadata' kwarg of dataclasses.field (#2384)
* 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`
2021-02-25 20:04:16 +00:00
Eric Jolibois ededd3ebf8 refactor(schema): support properly Literal in generated JSON schema (#2348)
* test: improve example

* refactor: use enum for Literal in JSON schema

* test: update test with new schema generation

* chore: add change file
2021-02-25 19:42:17 +00:00
Davis Kirkendall 2c2e238c19 Update mkdocs extensions to fix local syntax highlighting (#2401)
- Fixes #2400
2021-02-25 19:24:03 +00:00
Ofek Lev 4ddf4f14cd Properly retain types of Mapping subclasses (#2325)
* Properly retain types of Mapping subclasses

* Create 2325-ofek.md

* update with feedback

Co-Authored-By: Eric Jolibois <eric.jolibois@toucantoco.com>

* satisfy mypy?

* Update fields.py

Co-Authored-By: Eric Jolibois <eric.jolibois@toucantoco.com>

* show uncovered line numbers

* fix coverage

* update

* address feedback

* try

* update

Co-Authored-By: Eric Jolibois <eric.jolibois@toucantoco.com>

* rename test

* address feedback

Co-authored-by: Eric Jolibois <eric.jolibois@toucantoco.com>
Co-authored-by: Samuel Colvin <s@muelcolvin.com>
2021-02-25 17:27:50 +00:00