[pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci
This commit is contained in:
pre-commit-ci[bot] 2024-04-13 00:00:18 +00:00
parent 72ad6dc953
commit f4cd1ba0d6
813 changed files with 66015 additions and 58839 deletions

View file

@ -6,7 +6,6 @@
#
# $Id$
#
"""Provides classes to represent module version numbers (one class for
each style of version numbering). There are currently two such classes
implemented: StrictVersion and LooseVersion.
@ -25,9 +24,11 @@ Every version number class implements the following interface:
of the same class or a string (which will be parsed to an instance
of the same class, thus must follow the same rules)
"""
from __future__ import annotations
import re
class Version:
"""Abstract base class for version numbering classes. Just provides
constructor (__init__) and reproducer (__repr__), because those
@ -35,12 +36,12 @@ class Version:
rich comparisons to _cmp.
"""
def __init__ (self, vstring=None):
def __init__(self, vstring=None):
if vstring:
self.parse(vstring)
def __repr__ (self):
return "%s ('%s')" % (self.__class__.__name__, str(self))
def __repr__(self):
return "{} ('{}')".format(self.__class__.__name__, str(self))
def __eq__(self, other):
c = self._cmp(other)
@ -127,11 +128,12 @@ class StrictVersion (Version):
in the distutils documentation.
"""
version_re = re.compile(r'^(\d+) \. (\d+) (\. (\d+))? ([ab](\d+))?$',
re.VERBOSE | re.ASCII)
version_re = re.compile(
r'^(\d+) \. (\d+) (\. (\d+))? ([ab](\d+))?$',
re.VERBOSE | re.ASCII,
)
def parse (self, vstring):
def parse(self, vstring):
match = self.version_re.match(vstring)
if not match:
raise ValueError("invalid version number '%s'" % vstring)
@ -149,8 +151,7 @@ class StrictVersion (Version):
else:
self.prerelease = None
def __str__ (self):
def __str__(self):
if self.version[2] == 0:
vstring = '.'.join(map(str, self.version[0:2]))
@ -162,8 +163,7 @@ class StrictVersion (Version):
return vstring
def _cmp (self, other):
def _cmp(self, other):
if isinstance(other, str):
other = StrictVersion(other)
elif not isinstance(other, StrictVersion):
@ -197,7 +197,7 @@ class StrictVersion (Version):
else:
return 1
else:
assert False, "never get here"
assert False, 'never get here'
# end class StrictVersion
@ -301,18 +301,19 @@ class LooseVersion (Version):
component_re = re.compile(r'(\d+ | [a-z]+ | \.)', re.VERBOSE)
def __init__ (self, vstring=None):
def __init__(self, vstring=None):
if vstring:
self.parse(vstring)
def parse (self, vstring):
def parse(self, vstring):
# I've given up on thinking I can reconstruct the version string
# from the parsed tuple -- so I just store the string here for
# use by __str__
self.vstring = vstring
components = [x for x in self.component_re.split(vstring)
if x and x != '.']
components = [
x for x in self.component_re.split(vstring)
if x and x != '.'
]
for i, obj in enumerate(components):
try:
components[i] = int(obj)
@ -321,16 +322,13 @@ class LooseVersion (Version):
self.version = components
def __str__ (self):
def __str__(self):
return self.vstring
def __repr__ (self):
def __repr__(self):
return "LooseVersion ('%s')" % str(self)
def _cmp (self, other):
def _cmp(self, other):
if isinstance(other, str):
other = LooseVersion(other)
elif not isinstance(other, LooseVersion):