forked from Mirror/pmbootstrap
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:
parent
c38933f2e6
commit
a6025ed42a
1 changed files with 1 additions and 1 deletions
|
@ -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)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue