Skip to content

Commit 54d202f

Browse files
committed
refactor: Drop regex matching for version
1 parent 302d3f5 commit 54d202f

1 file changed

Lines changed: 9 additions & 10 deletions

File tree

mailjet_rest/utils/version.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313

1414
from __future__ import annotations
1515

16-
import re
17-
1816
from mailjet_rest._version import __version__ as package_version
1917

2018

@@ -27,15 +25,16 @@ def clean_version(version_str: str) -> tuple[int, ...]:
2725
Returns:
2826
tuple: A tuple representing the version of the package.
2927
"""
30-
if not version_str:
28+
try:
29+
parts = version_str.split(".")
30+
major = int(parts[0])
31+
minor = int(parts[1])
32+
# Strip any trailing prerelease tags (e.g., "1rc1" -> "1")
33+
patch = int("".join(c for c in parts[2] if c.isdigit()))
34+
except (IndexError, ValueError):
3135
return 0, 0, 0
32-
# Extract just the X.Y.Z part using regex
33-
match = re.match(r"^(\d+\.\d+\.\d+)", version_str)
34-
if match:
35-
version_part = match.group(1)
36-
return tuple(map(int, version_part.split(".")))
37-
38-
return 0, 0, 0
36+
else:
37+
return (major, minor, patch)
3938

4039

4140
# VERSION is a tuple of integers (1, 3, 2).

0 commit comments

Comments
 (0)