Thanks to visit codestin.com
Credit goes to github.com

Skip to content

441 update pydantic section of docs #442

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion docs/advanced/combine-pydantic-and-semver.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,23 @@ According to its homepage, `Pydantic <https://pydantic-docs.helpmanual.io>`_
"enforces type hints at runtime, and provides user friendly errors when data
is invalid."

To work with Pydantic>2.0, use the following steps:
If you are working with Pydantic>2.0 and pydantic-extra-types>=2.10.0 use the built in `_VersionPydanticAnnotation` type, which wraps the :class:`Version <semver.version.Version>` class.

.. code-block:: python

from pydantic import BaseModel

from pydantic_extra_types.server import _VersionPydanticAnnotation

class appVersion(BaseModel):
version: _VersionPydanticAnnotation

app_version = appVersion(version="1.2.3")

print(app_version.version)
# > 1.2.3

To work with Pydantic>2.0 and without pydantic-extra-types use the following example to define your own type:


1. Derive a new class from :class:`~semver.version.Version`
Expand Down