Repository: pydantic/pydantic-extra-types (language: python)

Issue:
Duplicate semantic versioning modules
In #195 pydantic_extra_types/semantic_version.py was added, followed by the nearly-identical pydantic_extra_types/semver.py in #199. Would it make sense to deduplicate this useful module?


Discussion / hints:
Hey @viccie30 nice catch, Yes its make sense 👍🏻 

PRs are welcome! 🚀 

Fix patch:
diff --git a/pydantic_extra_types/semver.py b/pydantic_extra_types/semver.py
index 46e6899..3418ec9 100644
--- a/pydantic_extra_types/semver.py
+++ b/pydantic_extra_types/semver.py
@@ -12,11 +12,17 @@
 else:
     from typing import Annotated  # pragma: no cover
 
+import warnings
+
 from pydantic import GetJsonSchemaHandler
 from pydantic.json_schema import JsonSchemaValue
 from pydantic_core import core_schema
 from semver import Version
 
+warnings.warn(
+    'Use from pydantic_extra_types.semver import SemanticVersion instead. Will be removed in 3.0.0.', DeprecationWarning
+)
+
 
 class _VersionPydanticAnnotation(Version):
     """
diff --git a/pyproject.toml b/pyproject.toml
index 899b9b5..89d416d 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -38,7 +38,7 @@ classifiers = [
     'Topic :: Internet',
 ]
 requires-python = '>=3.8'
-dependencies = ['pydantic>=2.5.2']
+dependencies = ['pydantic>=2.5.2','typing-extensions']
 dynamic = ['version']
 
 [project.optional-dependencies]
@@ -123,7 +123,8 @@ filterwarnings = [
     # This ignore will be removed when pycountry will drop py36 & support py311
     'ignore:::pkg_resources',
     # This ignore will be removed when pendulum fixes https://github.com/sdispater/pendulum/issues/834
-    'ignore:datetime.datetime.utcfromtimestamp.*:DeprecationWarning'
+    'ignore:datetime.datetime.utcfromtimestamp.*:DeprecationWarning',
+    ' ignore:Use from pydantic_extra_types.semver import SemanticVersion instead. Will be removed in 3.0.0.:DeprecationWarning'
 ]
 
 # configuring https://github.com/pydantic/hooky


Test patch:
diff --git a/tests/test_semantic_version.py b/tests/test_semantic_version.py
index dc79bef..4df76a3 100644
--- a/tests/test_semantic_version.py
+++ b/tests/test_semantic_version.py
@@ -12,12 +12,14 @@ class Application(BaseModel):
     return Application
 
 
-def test_valid_semantic_version(SemanticVersionObject):
-    application = SemanticVersionObject(version='1.0.0')
+@pytest.mark.parametrize('version', ['1.0.0', '1.0.0-alpha.1', '1.0.0-alpha.1+build.1', '1.2.3'])
+def test_valid_semantic_version(SemanticVersionObject, version):
+    application = SemanticVersionObject(version=version)
     assert application.version
-    assert application.model_dump() == {'version': '1.0.0'}
+    assert application.model_dump() == {'version': version}
 
 
-def test_invalid_semantic_version(SemanticVersionObject):
+@pytest.mark.parametrize('invalid_version', ['no dots string', 'with.dots.string', ''])
+def test_invalid_semantic_version(SemanticVersionObject, invalid_version):
     with pytest.raises(ValidationError):
-        SemanticVersionObject(version='Peter Maffay')
+        SemanticVersionObject(version=invalid_version)