Skip to content

Commit 1a5daa8

Browse files
committed
LegacyVersion: Consolidate typings
1 parent 3e1e5d1 commit 1a5daa8

File tree

1 file changed

+12
-18
lines changed

1 file changed

+12
-18
lines changed

src/libtmux/_compat.py

+12-18
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ def str_from_console(s: t.Union[str, bytes]) -> str:
3535

3636
try:
3737
import re
38+
from typing import Iterator, List, Tuple
3839

3940
from packaging.version import Version, _BaseVersion
4041

@@ -44,6 +45,8 @@ def str_from_console(s: t.Union[str, bytes]) -> str:
4445
### License: BSD, Accessed: Jan 14th, 2022
4546
###
4647

48+
LegacyCmpKey = Tuple[int, Tuple[str, ...]]
49+
4750
_legacy_version_component_re = re.compile(r"(\d+ | [a-z]+ | \.| -)", re.VERBOSE)
4851
_legacy_version_replacement_map = {
4952
"pre": "c",
@@ -53,8 +56,7 @@ def str_from_console(s: t.Union[str, bytes]) -> str:
5356
"dev": "@",
5457
}
5558

56-
def _parse_version_parts(s):
57-
# type: (str) -> Iterator[str]
59+
def _parse_version_parts(s: str) -> Iterator[str]:
5860
for part in _legacy_version_component_re.split(s):
5961
part = _legacy_version_replacement_map.get(part, part)
6062

@@ -70,9 +72,7 @@ def _parse_version_parts(s):
7072
# ensure that alpha/beta/candidate are before final
7173
yield "*final"
7274

73-
def _legacy_cmpkey(version):
74-
# type: (str) -> LegacyCmpKey
75-
75+
def _legacy_cmpkey(version: str) -> LegacyCmpKey:
7676
# We hardcode an epoch of -1 here. A PEP 440 version can only have a epoch
7777
# greater than or equal to 0. This will effectively put the LegacyVersion,
7878
# which uses the defacto standard originally implemented by setuptools,
@@ -81,7 +81,7 @@ def _legacy_cmpkey(version):
8181

8282
# This scheme is taken from pkg_resources.parse_version setuptools prior to
8383
# it's adoption of the packaging library.
84-
parts = [] # type: List[str]
84+
parts: List[str] = []
8585
for part in _parse_version_parts(version.lower()):
8686
if part.startswith("*"):
8787
# remove "-" before a prerelease tag
@@ -98,32 +98,26 @@ def _legacy_cmpkey(version):
9898
return epoch, tuple(parts)
9999

100100
class LegacyVersion(_BaseVersion):
101-
def __init__(self, version):
102-
# type: (str) -> None
101+
def __init__(self, version: str) -> None:
103102
self._version = str(version)
104103
self._key = _legacy_cmpkey(self._version)
105104

106-
def __str__(self):
107-
# type: () -> str
105+
def __str__(self) -> str:
108106
return self._version
109107

110-
def __repr__(self):
111-
# type: () -> str
108+
def __repr__(self) -> str:
112109
return "<LegacyVersion({0})>".format(repr(str(self)))
113110

114111
@property
115-
def public(self):
116-
# type: () -> str
112+
def public(self) -> str:
117113
return self._version
118114

119115
@property
120-
def base_version(self):
121-
# type: () -> str
116+
def base_version(self) -> str:
122117
return self._version
123118

124119
@property
125-
def epoch(self):
126-
# type: () -> int
120+
def epoch(self) -> int:
127121
return -1
128122

129123
LooseVersion = LegacyVersion

0 commit comments

Comments
 (0)