Skip to content

Commit

Permalink
- resolving "_unpack_version" has incompatible type "int" problem i…
Browse files Browse the repository at this point in the history
…n `_unpack_version` method

- `"` are sent back to `'` (apparently my company's formatter `black` is not compatible with `pydocstyle`, and mine integration with VSCode has messed with kombu's repository)
  • Loading branch information
couzhei committed Aug 21, 2024
1 parent bf35400 commit c044dbe
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 27 deletions.
30 changes: 15 additions & 15 deletions kombu/utils/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
from kombu import version_info_t


def escape_regex(p, white=""):
def escape_regex(p, white=''):
# type: (str, str) -> str
"""Escape string for use within a regular expression."""
# what's up with re.escape? that code must be neglected or something
return "".join(
c if c.isalnum() or c in white else ("\\000" if c == "\000" else "\\" + c)
return ''.join(
c if c.isalnum() or c in white else ('\\000' if c == '\000' else '\\' + c)
for c in p
)

Expand Down Expand Up @@ -72,11 +72,11 @@ def version_string_as_tuple(version: str) -> version_info_t:
------
ValueError: If the version string is invalid and does not match the expected pattern.
"""
pattern = r"^(\d+)" # catching the major version (mandatory)
pattern += r"(?:\.(\d+))?" # optionally catching the minor version
pattern += r"(?:\.(\d+))?" # optionally catching the micro version
pattern += r"(?:\.*([a-zA-Z+-][\da-zA-Z+-]*))?" # optionally catching the release level (starting with a letter, + or -) after a dot
pattern += r"(?:\.(.*))?" # optionally catching the serial number after a dot
pattern = r'^(\d+)' # catching the major version (mandatory)
pattern += r'(?:\.(\d+))?' # optionally catching the minor version
pattern += r'(?:\.(\d+))?' # optionally catching the micro version
pattern += r'(?:\.*([a-zA-Z+-][\da-zA-Z+-]*))?' # optionally catching the release level (starting with a letter, + or -) after a dot
pattern += r'(?:\.(.*))?' # optionally catching the serial number after a dot

# applying the regex pattern to the input version string
match = re.match(pattern, version)
Expand All @@ -88,24 +88,24 @@ def version_string_as_tuple(version: str) -> version_info_t:
major = int(match.group(1))
minor = int(match.group(2)) if match.group(2) else 0
micro = int(match.group(3)) if match.group(3) else 0
releaselevel = match.group(4) if match.group(4) else ""
serial = match.group(5) if match.group(5) else ""
releaselevel = match.group(4) if match.group(4) else ''
serial = match.group(5) if match.group(5) else ''

return _unpack_version(major, minor, micro, releaselevel, serial)


def _unpack_version(
major: str,
major: str | int = 0,
minor: str | int = 0,
micro: str | int = 0,
releaselevel: str = "",
serial: str = "",
releaselevel: str = '',
serial: str = '',
) -> version_info_t:
return version_info_t(int(major), int(minor), micro, releaselevel, serial)
return version_info_t(int(major), int(minor), int(micro), releaselevel, serial)


def _splitmicro(
micro: str, releaselevel: str = "", serial: str = ""
micro: str, releaselevel: str = '', serial: str = ''
) -> tuple[int, str, str]:
for index, char in enumerate(micro):
if not char.isdigit():
Expand Down
24 changes: 12 additions & 12 deletions t/unit/utils/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@ def test_dir():


@pytest.mark.parametrize(
"version,expected",
'version,expected',
[
("3", version_info_t(3, 0, 0, "", "")),
("3.3", version_info_t(3, 3, 0, "", "")),
("3.3.1", version_info_t(3, 3, 1, "", "")),
("3.3.1a3", version_info_t(3, 3, 1, "a3", "")),
("3.3.1.a3.40c32", version_info_t(3, 3, 1, "a3", "40c32")),
("4.0.0+beta.3.47.g4f1a05b", version_info_t(
4, 0, 0, "+beta", "3.47.g4f1a05b")),
("4.0.0-beta3.47.g4f1a05b", version_info_t(
4, 0, 0, "-beta3", "47.g4f1a05b")),
("4.0.1-alpha.3+40c32", version_info_t(4, 0, 1, "-alpha", "3+40c32")),
("0+beta3.14159265", version_info_t(0, 0, 0, "+beta3", "14159265")),
('3', version_info_t(3, 0, 0, '', '')),
('3.3', version_info_t(3, 3, 0, '', '')),
('3.3.1', version_info_t(3, 3, 1, '', '')),
('3.3.1a3', version_info_t(3, 3, 1, 'a3', '')),
('3.3.1.a3.40c32', version_info_t(3, 3, 1, 'a3', '40c32')),
('4.0.0+beta.3.47.g4f1a05b', version_info_t(
4, 0, 0, '+beta', '3.47.g4f1a05b')),
('4.0.0-beta3.47.g4f1a05b', version_info_t(
4, 0, 0, '-beta3', '47.g4f1a05b')),
('4.0.1-alpha.3+40c32', version_info_t(4, 0, 1, '-alpha', '3+40c32')),
('0+beta3.14159265', version_info_t(0, 0, 0, '+beta3', '14159265')),
],
)
def test_version_string_as_tuple(version, expected):
Expand Down

0 comments on commit c044dbe

Please sign in to comment.