Skip to content

Commit fda2873

Browse files
authored
Merge pull request #420 from python-semver/classvar
Introduce ClassVar type
2 parents 50532e7 + 6a90bd3 commit fda2873

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

changelog.d/pr420.trivial.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Introduce :py:class:`~typing.ClassVar` for some :class:`~semver.version.Version`
2+
class variables, mainly :data:`~semver.version.Version.NAMES` and some private.

pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ requires = [
1414
build-backend = "setuptools.build_meta"
1515

1616

17-
1817
[tool.black]
1918
line-length = 88
2019
target-version = ['py37', 'py38', 'py39', 'py310', 'py311']

src/semver/version.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44
from functools import wraps
55
from typing import (
66
Any,
7+
ClassVar,
78
Dict,
89
Iterable,
910
Optional,
11+
Pattern,
1012
SupportsInt,
1113
Tuple,
1214
Union,
@@ -72,12 +74,14 @@ class Version:
7274
__slots__ = ("_major", "_minor", "_patch", "_prerelease", "_build")
7375

7476
#: The names of the different parts of a version
75-
NAMES = tuple([item[1:] for item in __slots__])
77+
NAMES: ClassVar[Tuple[str, ...]] = tuple([item[1:] for item in __slots__])
7678

7779
#: Regex for number in a prerelease
78-
_LAST_NUMBER = re.compile(r"(?:[^\d]*(\d+)[^\d]*)+")
80+
_LAST_NUMBER: ClassVar[Pattern] = re.compile(r"(?:[^\d]*(\d+)[^\d]*)+")
7981
#: Regex template for a semver version
80-
_REGEX_TEMPLATE = r"""
82+
_REGEX_TEMPLATE: ClassVar[
83+
str
84+
] = r"""
8185
^
8286
(?P<major>0|[1-9]\d*)
8387
(?:
@@ -99,12 +103,12 @@ class Version:
99103
$
100104
"""
101105
#: Regex for a semver version
102-
_REGEX = re.compile(
106+
_REGEX: ClassVar[Pattern] = re.compile(
103107
_REGEX_TEMPLATE.format(opt_patch="", opt_minor=""),
104108
re.VERBOSE,
105109
)
106110
#: Regex for a semver version that might be shorter
107-
_REGEX_OPTIONAL_MINOR_AND_PATCH = re.compile(
111+
_REGEX_OPTIONAL_MINOR_AND_PATCH: ClassVar[Pattern] = re.compile(
108112
_REGEX_TEMPLATE.format(opt_patch="?", opt_minor="?"),
109113
re.VERBOSE,
110114
)

0 commit comments

Comments
 (0)