Message258325
grp.getgrgid is capable of accepting a string:
from grp import getgrgid
print(getgrgid('0'))
However, pwd.getpwuid can't do the same:
from pwd import getpwuid
print(getpwuid('0'))
Traceback (most recent call last):
File "getpwuid_test.py", line 2, in <module>
print(getpwuid('0'))
TypeError: an integer is required
This seems to be because inside Modules/pwdmodule.c, getpwuid uses PyNumber_ParseTuple with a converter that uses PyNumber_Index to get a Python integer, and that raises an exception on failure.
However, in Modules/grpmodule.c, grp_getgrgid uses PyNumber_Long (Or PyNumber_Int for an old enough Python) as a conversion first, and as the documentation says at https://docs.python.org/3/c-api/number.html, this is the equivalent of running int(o), which can convert a string to an integer. Only then is it given to PyNumber_Index, by way of a helper function _Py_Gid_Converter
Should these have different behaviours? Is there a reason for the difference?
The behaviour of getgrgid seems more helpful, and it's odd that it doesn't apply to both functions. Is this undesirable behaviour in getgrgid or getpwuid? |
|
Date |
User |
Action |
Args |
2016-01-15 19:48:25 | SimonFr | set | recipients:
+ SimonFr |
2016-01-15 19:48:25 | SimonFr | set | messageid: <1452887305.34.0.0492943983639.issue26129@psf.upfronthosting.co.za> |
2016-01-15 19:48:25 | SimonFr | link | issue26129 messages |
2016-01-15 19:48:24 | SimonFr | create | |
|