Skip to content

Commit 861b7ea

Browse files
jbkronertomschr
authored andcommitted
update docs
1 parent d8813b6 commit 861b7ea

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

docs/advanced/combine-pydantic-and-semver.rst

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,23 @@ According to its homepage, `Pydantic <https://pydantic-docs.helpmanual.io>`_
99
"enforces type hints at runtime, and provides user friendly errors when data
1010
is invalid."
1111

12-
To work with Pydantic>2.0, use the following steps:
12+
If you are working with Pydantic>2.0 and pydantic-extra-types>=2.10.0 you can use the built in `_VersionPydanticAnnotation` type, which wraps the `python-semver` `Version` type.
13+
14+
.. code-block:: python
15+
16+
from pydantic import BaseModel
17+
18+
from pydantic_extra_types.server import _VersionPydanticAnnotation
19+
20+
class appVersion(BaseModel):
21+
version: _VersionPydanticAnnotation
22+
23+
app_version = appVersion(version="1.2.3")
24+
25+
print(app_version.version)
26+
# > 1.2.3
27+
28+
To work with Pydantic>2.0 and without pydantic-extra-types you can use the following example to define your own type:
1329

1430

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

0 commit comments

Comments
 (0)