10000 441 update pydantic section of docs (#442) · python-semver/python-semver@cc5b1d3 · GitHub
[go: up one dir, main page]

Skip to content

Commit cc5b1d3

Browse files
jbkronertomschr
andauthored
441 update pydantic section of docs (#442)
* Update docs/advanced/combine-pydantic-and-semver.rst * Update example with pydantic 2.10.5 semantic_version type --------- Co-authored-by: Tom Schraitle <tomschr@users.noreply.github.com>
1 parent d8813b6 commit cc5b1d3

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,22 @@ 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.5 use the built in `SemanticVersion` type, which wraps the :class:`Version <semver.version.Version>` class.
13+
14+
.. code-block:: python
15+
16+
from pydantic import BaseModel
17+
from pydantic_extra_types.semantic_version import SemanticVersion
18+
19+
class appVersion(BaseModel):
20+
version: SemanticVersion
21+
22+
app_version = appVersion(version="1.2.3")
23+
24+
print(app_version.version)
25+
# > 1.2.3
26+
27+
To work with Pydantic>2.0 and without pydantic-extra-types use the following example to define your own type:
1328

1429

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

0 commit comments

Comments
 (0)
0