From cc5b1d370f74c7a1775da5cfcbaca954bbb9f3bd Mon Sep 17 00:00:00 2001 From: Jim Kroner <9373098+jbkroner@users.noreply.github.com> Date: Fri, 4 Jul 2025 17:23:09 -0400 Subject: [PATCH] 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 --- docs/advanced/combine-pydantic-and-semver.rst | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/docs/advanced/combine-pydantic-and-semver.rst b/docs/advanced/combine-pydantic-and-semver.rst index c7566e12..975fb418 100644 --- a/docs/advanced/combine-pydantic-and-semver.rst +++ b/docs/advanced/combine-pydantic-and-semver.rst @@ -9,7 +9,22 @@ According to its homepage, `Pydantic `_ "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.5 use the built in `SemanticVersion` type, which wraps the :class:`Version ` class. + + .. code-block:: python + + from pydantic import BaseModel + from pydantic_extra_types.semantic_version import SemanticVersion + + class appVersion(BaseModel): + version: SemanticVersion + + 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`