Skip to content

Commit 79a18aa

Browse files
committed
update docs
1 parent 4815626 commit 79a18aa

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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy