Author SimonFr
Recipients SimonFr
Date 2016-01-15.19:48:24
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
grp.getgrgid is capable of accepting a string:

from grp import getgrgid

However, pwd.getpwuid can't do the same:

from pwd import getpwuid

Traceback (most recent call last):
  File "", line 2, in <module>
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, 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:25SimonFrsetrecipients: + SimonFr
2016-01-15 19:48:25SimonFrsetmessageid: <>
2016-01-15 19:48:25SimonFrlinkissue26129 messages
2016-01-15 19:48:24SimonFrcreate