Commit Graph

365 Commits

Author SHA1 Message Date
Yurii Karabas ee0b2e2153 Fix issue with ClassVar parsing (#3403)
* Fix issue with ClassVar parsing

* Fix lint error

* Simplify test

* Fix condition and test
2021-11-18 23:40:15 +01:00
Sebastián Ramírez 45db4ad3aa Add autocomplete support for VS Code, via dataclass_transform (#2721)
*  Add autocomplete support for VS Code, via dataclass_transform

* 📝 Update changes

* 📝 Add docs for VS Code

* 📝 Clarify strict type error checks alternatives, include example with cast()

* ♻️ Update BaseSettings annotation to improve editor support

keeping editor support for BaseSetting's custom Config, but preventing __config__ from showing in constructor on editors supporting dataclass_transform

* 🎨 Remove unused type: ignore comment

* 🎨 Update type annotations for BaseSettings and BaseModel to use ClassVar where suitable

to improve editor support with type annotations and dataclass_transform

* 🎨 Apply ClassVars again

* 📝 Simplify VS Code docs terms

refer mainly to Pylance and clarify the relationship with Pyright

* 📝 Add link to Pylance FAQ

Co-authored-by: PrettyWood <em.jolibois@gmail.com>
2021-09-06 12:13:02 +02:00
Eric Jolibois 5bc1fcfb92 feat: support custom extra in validate_arguments (#3177) 2021-09-06 00:44:16 +02:00
Eric Jolibois c4e793b767 fix: make validate_arguments work with Config.validate_all (#3176)
* fix: make `validate_arguments` work with `Config.validate_all`

* coverage
2021-09-06 00:33:36 +02:00
Yurii Karabas 63e42db921 Fix bug when mypy plugin fail on construct method call (#2767)
* Fix bug when mypy plugin fail on construct method call

* Update type annotation for __config__ field

* Remove type ignore

* Update changes/2753-uriyyo.md

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

Co-authored-by: Eric Jolibois <em.jolibois@gmail.com>
2021-09-05 11:29:13 +02:00
John Walk 0c2f69c500 Toml support for pydantic-mypy plugin config (#2908)
* add toml reader

* fix path

* skip configparser step

* fix quotes

* full pyproject.toml check

* add doc note

* cleaner formatting, raise ValueError for non-bool

* fix tests

* add bad config test case

* add changelog file.

* bump mypy to 0.902

* tweak change MD, fix formatting in requirements

* import check around toml

* switch to tomli for parsing to match mypy dependency

* import check around toml/tomli

* add note on tomli usage

* more succinct changelog entry

* fix quotes in changelog

* linting fixes, remove unnecessary stub install

* mypy checks on mypy plugin file

* wrongly placed pragma no cover

Co-authored-by: PrettyWood <em.jolibois@gmail.com>
2021-09-05 11:25:47 +02:00
Jamey Sharp 72d4f30f0a Resolve postponed NamedTuple annotations (#2760) (#2761)
Thanks to @PrettyWood for pointing me to the right place to fix this!

Since I was told that both NamedTuple and TypedDict use the same
__pydantic_model__ machinery that dataclasses do, I checked and found
that TypedDict had the same bug, and fixed that too.

Tests for both issues are included, which fail without the associated
fixes being applied.
2021-09-04 23:45:23 +02:00
Yurii Karabas 1aa22e199f Add ability to use Counter type (#2806)
Co-authored-by: Eric Jolibois <em.jolibois@gmail.com>
2021-09-04 23:41:09 +02:00
sergejkozin 257908628f fix(schema): fix schema generation for Deque field (#2811)
* fix(schema): fix schema generation for `Deque` field

* add change description
2021-09-04 22:45:40 +02:00
Xavier Defrang 161b000c7e Accept empty query/fragment URL parts (#2888)
* Accept empty query/fragment URL parts

* forbid two # in fragment

Co-authored-by: PrettyWood <em.jolibois@gmail.com>
2021-09-04 21:06:08 +02:00
Piotr Gnus abbad5e88c Added dark color scheme for docs (#2913)
* Added dark color scheme for docs

Added alternative, dark color scheme for docs, which should be automatically activated if user's browser presents the `prefers-color-scheme: dark` media query.

* switch icons

* add change file

Co-authored-by: PrettyWood <em.jolibois@gmail.com>
2021-09-04 20:37:42 +02:00
Pax e431604654 clarify docs on validation and strict type checking (#2855)
* clarify docs on validation and strict type checking

Related: Issue#578

Co-authored-by: cknoll <unknown@exampleemail.com>
Co-authored-by: PyAntony <unknown@exampleemail.com>

* add change.md for PR#2855

* docs: explicitly specify _partial_ support

* chore: update formatting of change description

Co-authored-by: cknoll <unknown@exampleemail.com>
2021-09-04 19:58:47 +02:00
Pax 4ac2501477 mention 3.8 requirement in contrib docs (#2856)
* mention 3.8 requirement in contrib docs

* add change.md for PR#2856

* docs: fix grammar and wording
2021-09-04 19:55:40 +02:00
Christopher Bartz 428f1e4d34 Parse JSON for union type with complex subfields (#2936) (#2970)
* Parse JSON for union type with complex subfields (#2936)

* style

* simplify

Co-authored-by: Christopher Bartz <c.bartz@zbw.eu>
Co-authored-by: PrettyWood <em.jolibois@gmail.com>
2021-09-04 19:53:32 +02:00
Hmvp 22849ee049 Fix error when using slots with multiple inheritance (#2989)
* Fix error when using slots with multiple inheritance

* typo

* typing

Co-authored-by: PrettyWood <em.jolibois@gmail.com>
2021-09-04 18:32:29 +02:00
Jacob Hayes acb4ff3744 Fix support for using a subclass of an annotation as a default (#3018)
* Add test for type hint subclass as default

* Fix support for using a subclass of an annotation as a default

* Add changes file

* add check in test

Co-authored-by: PrettyWood <em.jolibois@gmail.com>
2021-09-04 18:11:17 +02:00
Matthew Hughes e9327b85fc Add a TypedDict class for error objects (#3038)
* Add a TypedDict class for error objects

This adds more specific typing for the dictionaries in
`ValidationError.errors()`. This shouldn't introduce any functional
change.

* quotes

* split required and not required keys

* type but be a class

* workaround cython (can't wait for v3)

Co-authored-by: PrettyWood <em.jolibois@gmail.com>
2021-09-04 17:33:48 +02:00
Eric Jolibois 020a0219eb fix: make create_model_from_typeddict mypy compliant (#3047)
* fix: make `create_model_from_typeddict` mypy compliant

closes #3008

* add comment
2021-09-04 16:59:23 +02:00
Eric Jolibois f5a9f4fbe3 feat: handle object type (#3062) 2021-09-04 16:40:14 +02:00
Roger Collins 268c3cc41f Fix: _pydantic_post_init() reassigns __dict__ and removes properties (#3093)
* Fix: _pydantic_post_init() reassigns __dict__ and removes properties added to the object, for example in __new__(), breaking integration with SQLAlchemy and other libraries #3043

* Added changes file
2021-09-04 16:32:22 +02:00
Grégoire Charvet 黑瓜 97a4176110 Correctly parse generic models with Json[T] (#2987)
* Fix 2860

When dealing with JsonWrapper, replace the inner type when constructing
a a generic model.

* tweak and schema test

Co-authored-by: PrettyWood <em.jolibois@gmail.com>
2021-09-04 11:36:29 +02:00
Yurii Karabas b26d6f925b mypy: Add create_model overload (#2748)
* Add create_model overload

* Add changes

* fix: import

Co-authored-by: PrettyWood <em.jolibois@gmail.com>
2021-09-04 04:53:49 +02:00
Eric Jolibois 6b6116054a fix: nested literal with constraints (#2794)
* fix: nested literal with constraints

* docs: add change file
2021-09-04 04:36:42 +02:00
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