Skip to content

Commit 2e48629

Browse files
committed
Introduce ClassVar type
Use it for class variables NAMES, _LAST_NUMBER, _REGEX_TEMPLATE, _REGEX, and _REGEX_OPTIONAL_MINOR_AND_PATCH.
1 parent 50532e7 commit 2e48629

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

pyproject.toml

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

1616

17+
[tool.mypy]
18+
# ignore-missing-imports = true
19+
# check-untyped-defs = true
20+
# strict = true
21+
pretty = true
22+
1723

1824
[tool.black]
1925
line-length = 88

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
)

tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ commands = flake8 {posargs:}
4949
description = Check code style
5050
basepython = python3
5151
deps = mypy
52-
commands = mypy {posargs:--ignore-missing-imports --check-untyped-defs src}
52+
commands = mypy {posargs:src}
5353

5454

5555
[testenv:docstrings]

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy