This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author SimonFr
Recipients SimonFr
Date 2016-01-15.19:48:24
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1452887305.34.0.0492943983639.issue26129@psf.upfronthosting.co.za>
In-reply-to
Content
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?
History
Date User Action Args
2016-01-15 19:48:25SimonFrsetrecipients: + SimonFr
2016-01-15 19:48:25SimonFrsetmessageid: <1452887305.34.0.0492943983639.issue26129@psf.upfronthosting.co.za>
2016-01-15 19:48:25SimonFrlinkissue26129 messages
2016-01-15 19:48:24SimonFrcreate