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 5d796b5678/src/version.c (L101)
This commit is contained in:
Newbyte 2024-12-20 14:23:09 +01:00
parent c38933f2e6
commit a6025ed42a
No known key found for this signature in database
GPG key ID: 5AE7F5513E0885CB

View file

@ -170,7 +170,7 @@ def get_token(previous, rest):
# Append chars or parse suffix # Append chars or parse suffix
elif previous == "letter": elif previous == "letter":
value = rest[0] value = ord(rest[0])
rest = rest[1:] rest = rest[1:]
elif previous == "suffix": elif previous == "suffix":
(rest, value, invalid_suffix) = parse_suffix(rest) (rest, value, invalid_suffix) = parse_suffix(rest)