You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Historically, Python 2 had two data types for strings:
str to represent sequences of chars, where each char is in the range 0-255
unicode to represent unicode strings
At the C level, the API functions related to str were called PyString_* and functions related to unicode were called PyUnicode_*.
The modern Python 3 has the same data types but with different names:
bytes is equivalent to the old str. The C functions are called PyBytes_*
str is equivalent to the old unicode. For the historical reasons explained above, the C functions are still called PyUnicode_*.
For HPy we have basically 3 options:
follow the CPython convention and call them HPyBytes_* and HPyUnicode_*
fix the mess and call them HPyBytes_* and HPyStr_* (or possibly HPyString_*, but I think that HPyStr is much better)
middle ground solution, which could be useful for other parts of the API. We could declare HPyStr_* as the official API, but also provide a separate header (maybe hpy/compat.h or hpy/cpycompat.h?) which maps HPyUnicode_* to the equivalent HPyStr_*, possibly giving a warning.
HPyUnicode_* pros: it is easier for people to port their code from Python/C to HPy, and to compare to the CPython docs
HPyStr_* pros: it is cleaner and more consistent with the rest of the API.
Personally, I think that the best is the middle-ground solution.
The text was updated successfully, but these errors were encountered:
Historically, Python 2 had two data types for strings:
str
to represent sequences of chars, where each char is in the range 0-255unicode
to represent unicode stringsAt the C level, the API functions related to
str
were calledPyString_*
and functions related tounicode
were calledPyUnicode_*
.The modern Python 3 has the same data types but with different names:
bytes
is equivalent to the oldstr
. The C functions are calledPyBytes_*
str
is equivalent to the oldunicode
. For the historical reasons explained above, the C functions are still calledPyUnicode_*
.For HPy we have basically 3 options:
HPyBytes_*
andHPyUnicode_*
HPyBytes_*
andHPyStr_*
(or possiblyHPyString_*
, but I think thatHPyStr
is much better)HPyStr_*
as the official API, but also provide a separate header (maybehpy/compat.h
orhpy/cpycompat.h
?) which mapsHPyUnicode_*
to the equivalentHPyStr_*
, possibly giving a warning.HPyUnicode_*
pros: it is easier for people to port their code from Python/C to HPy, and to compare to the CPython docsHPyStr_*
pros: it is cleaner and more consistent with the rest of the API.Personally, I think that the best is the middle-ground solution.
The text was updated successfully, but these errors were encountered: