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.

classification
Title: grp.struct_group is not hashable
Type: behavior Stage: resolved
Components: Versions: Python 3.4, Python 3.5, Python 2.7
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: ethan.furman, serhiy.storchaka
Priority: normal Keywords: patch

Created on 2014-09-29 17:19 by ethan.furman, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
issue22513.stoneleaf.01.patch ethan.furman, 2014-09-29 17:49 review
Messages (4)
msg227811 - (view) Author: Ethan Furman (ethan.furman) * (Python committer) Date: 2014-09-29 17:19
First, the behavior for pwd.struct_passwd:
-----------------------------------------
--> pwd.getpwuid(1000)
pwd.struct_passwd(pw_name='ethan', pw_passwd='x', pw_uid=1000, pw_gid=1000, pw_gecos='Ethan Furman,,,', pw_dir='/home/ethan', pw_shell='/bin/bash')

--> set(pwd.getpwuid(1000))
set(['/bin/bash', 1000, 'Ethan Furman,,,', '/home/ethan', 'ethan', 'x'])

--> set([pwd.getpwuid(1000)])
set([pwd.struct_passwd(pw_name='ethan', pw_passwd='x', pw_uid=1000, pw_gid=1000, pw_gecos='Ethan Furman,,,', pw_dir='/home/ethan', pw_shell='/bin/bash')])

Now, the behavior for grp.struct_group:
--------------------------------------
--> grp.getgrgid(1000)
grp.struct_group(gr_name='ethan', gr_passwd='x', gr_gid=1000, gr_mem=[])

--> set(grp.getgrgid(1000))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unhashable type: 'list'

--> set([grp.getgrgid(1000)])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unhashable type: 'list'


At the very least the error message is wrong (it's not a list), and at the most grp.struct_group should be hashable  -- i.e. we should be able to have a set of groups.
msg227813 - (view) Author: Ethan Furman (ethan.furman) * (Python committer) Date: 2014-09-29 17:49
Test added.
msg227816 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2014-09-29 19:02
This is because grp.struct_group contains unhashable component (a list).

Same behavior with tuple:

>>> tuple(grp.getgrgid(1000))
('serhiy', 'x', 1000, [])
>>> set(tuple(grp.getgrgid(1000)))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unhashable type: 'list'
>>> set([tuple(grp.getgrgid(1000))])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unhashable type: 'list'

Instead a set of grp.struct_group, create a dict, which maps group name to grp.struct_group.
msg227817 - (view) Author: Ethan Furman (ethan.furman) * (Python committer) Date: 2014-09-29 19:16
Thanks, Serhiy.
History
Date User Action Args
2022-04-11 14:58:08adminsetgithub: 66703
2014-09-29 19:16:15ethan.furmansetstatus: open -> closed
resolution: not a bug
messages: + msg227817

stage: needs patch -> resolved
2014-09-29 19:02:29serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg227816
2014-09-29 17:49:48ethan.furmansetfiles: + issue22513.stoneleaf.01.patch
keywords: + patch
messages: + msg227813

stage: needs patch
2014-09-29 17:19:31ethan.furmancreate