From 6a90bd3a55e13715e309c4933740a16eee534e3a Mon Sep 17 00:00:00 2001 From: Tom Schraitle Date: Sun, 23 Jul 2023 09:32:43 +0200 Subject: [PATCH] Introduce ClassVar type Use it for class variables NAMES, _LAST_NUMBER, _REGEX_TEMPLATE, _REGEX, and _REGEX_OPTIONAL_MINOR_AND_PATCH. --- changelog.d/pr420.trivial.rst | 2 ++ pyproject.toml | 1 - src/semver/version.py | 14 +++++++++----- 3 files changed, 11 insertions(+), 6 deletions(-) create mode 100644 changelog.d/pr420.trivial.rst diff --git a/changelog.d/pr420.trivial.rst b/changelog.d/pr420.trivial.rst new file mode 100644 index 00000000..234ecdbe --- /dev/null +++ b/changelog.d/pr420.trivial.rst @@ -0,0 +1,2 @@ +Introduce :py:class:`~typing.ClassVar` for some :class:`~semver.version.Version` +class variables, mainly :data:`~semver.version.Version.NAMES` and some private. diff --git a/pyproject.toml b/pyproject.toml index 6b12deb0..e26c034c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -14,7 +14,6 @@ requires = [ build-backend = "setuptools.build_meta" - [tool.black] line-length = 88 target-version = ['py37', 'py38', 'py39', 'py310', 'py311'] diff --git a/src/semver/version.py b/src/semver/version.py index 96040cef..c84f2328 100644 --- a/src/semver/version.py +++ b/src/semver/version.py @@ -4,9 +4,11 @@ from functools import wraps from typing import ( Any, + ClassVar, Dict, Iterable, Optional, + Pattern, SupportsInt, Tuple, Union, @@ -72,12 +74,14 @@ class Version: __slots__ = ("_major", "_minor", "_patch", "_prerelease", "_build") #: The names of the different parts of a version - NAMES = tuple([item[1:] for item in __slots__]) + NAMES: ClassVar[Tuple[str, ...]] = tuple([item[1:] for item in __slots__]) #: Regex for number in a prerelease - _LAST_NUMBER = re.compile(r"(?:[^\d]*(\d+)[^\d]*)+") + _LAST_NUMBER: ClassVar[Pattern] = re.compile(r"(?:[^\d]*(\d+)[^\d]*)+") #: Regex template for a semver version - _REGEX_TEMPLATE = r""" + _REGEX_TEMPLATE: ClassVar[ + str + ] = r""" ^ (?P0|[1-9]\d*) (?: @@ -99,12 +103,12 @@ class Version: $ """ #: Regex for a semver version - _REGEX = re.compile( + _REGEX: ClassVar[Pattern] = re.compile( _REGEX_TEMPLATE.format(opt_patch="", opt_minor=""), re.VERBOSE, ) #: Regex for a semver version that might be shorter - _REGEX_OPTIONAL_MINOR_AND_PATCH = re.compile( + _REGEX_OPTIONAL_MINOR_AND_PATCH: ClassVar[Pattern] = re.compile( _REGEX_TEMPLATE.format(opt_patch="?", opt_minor="?"), re.VERBOSE, ) 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