From a6025ed42a8227f3063c7dd2441b5635fc516fdf Mon Sep 17 00:00:00 2001 From: Newbyte Date: Fri, 20 Dec 2024 14:23:09 +0100 Subject: [PATCH] pmb.parse.version: Convert rest[0] to integer before storing it in value (MR 2514) Previously, value would sometimes be a string despite the docstring clearly stating that it should be an integer. This seems to have been a consequence of literally copying the original C code without considering that strings work differently between the languages, where the original assigning a character in a string to an integer results in the integer having the ASCII value of that character, in Python you just get the string value of that character. As such, match the original implementation by explicitly converting from a string to an integer using ord(), which gives the Unicode code of the provided character. It is not clear to me why this disparity didn't cause any issues beyond type errors found by mypy. See https://gitlab.alpinelinux.org/alpine/apk-tools/-/blob/5d796b567819ce91740fcdea7cbafecbda65d8f3/src/version.c#L101 --- pmb/parse/version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pmb/parse/version.py b/pmb/parse/version.py index a554b891..44a6a08e 100644 --- a/pmb/parse/version.py +++ b/pmb/parse/version.py @@ -170,7 +170,7 @@ def get_token(previous, rest): # Append chars or parse suffix elif previous == "letter": - value = rest[0] + value = ord(rest[0]) rest = rest[1:] elif previous == "suffix": (rest, value, invalid_suffix) = parse_suffix(rest)