From 35da4f6715ceaf251d6358de927547b5143a8184 Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Tue, 31 Jan 2023 08:59:49 -0500 Subject: [PATCH] Fix pydantic/semver example The current example, when used with semver 3.0.0.dev4 and pydantic 1.10.4, produces the following error: pydantic.errors.ConfigError: Invalid signature for validator >: (version: Union[str, bytes], optional_minor_and_patch: bool = False) -> 'Version', should be: (value, values, config, field), "values", "config" and "field" are all optional. This commit fixes the example in the documentation so that it works and does not raise an error. --- changelog.d/pr392.doc.rst | 1 + docs/advanced/combine-pydantic-and-semver.rst | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 changelog.d/pr392.doc.rst diff --git a/changelog.d/pr392.doc.rst b/changelog.d/pr392.doc.rst new file mode 100644 index 00000000..e542cef9 --- /dev/null +++ b/changelog.d/pr392.doc.rst @@ -0,0 +1 @@ +Fix the example in the documentation for combining semver and pydantic. diff --git a/docs/advanced/combine-pydantic-and-semver.rst b/docs/advanced/combine-pydantic-and-semver.rst index a9249daf..a00c2cff 100644 --- a/docs/advanced/combine-pydantic-and-semver.rst +++ b/docs/advanced/combine-pydantic-and-semver.rst @@ -17,10 +17,14 @@ To work with Pydantic, use the following steps: from semver import Version class PydanticVersion(Version): + @classmethod + def _parse(cls, version): + return cls.parse(version) + @classmethod def __get_validators__(cls): """Return a list of validator methods for pydantic models.""" - yield cls.parse + yield cls._parse @classmethod def __modify_schema__(cls, field_schema):