Skip to content

gh-155358: Use named attributes with pwd and grp modules - #155362

Open
vstinner wants to merge 2 commits into
python:mainfrom
vstinner:tuple_api_pwd_grp
Open

gh-155358: Use named attributes with pwd and grp modules#155362
vstinner wants to merge 2 commits into
python:mainfrom
vstinner:tuple_api_pwd_grp

Conversation

@vstinner

@vstinner vstinner commented Aug 7, 2026

Copy link
Copy Markdown
Member
  • Replace pwd[0] with pwd.pw_name
  • Replace pwd[2] with pwd.pw_uid
  • Replace grp[0] with grp.gr_name
  • Replace grp[2] with grp.gr_gid

* Replace pwd[0] with pwd.pw_name
* Replace pwd[2] with pwd.pw_uid
* Replace grp[0] with grp.gr_name
* Replace grp[2] with grp.gr_gid

@giampaolo giampaolo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Perhaps the only thing I would add is a test which checks that assert grp.getgrgid(...)[0] == grp.getgrgid(...).gr_name (and others). I didn't check, maybe it's already there.

Also, while you're there, perhaps you want to also make the replacement in other places? Like Lib/http/server.py (grep for getpwuid, getgrgid, and others under Lib/ to find all).

* Replace pwd[3] with pwd.pw_gid
@vstinner
vstinner requested review from a team and ericsnowcurrently as code owners August 7, 2026 21:04
@vstinner

vstinner commented Aug 7, 2026

Copy link
Copy Markdown
Member Author

Perhaps the only thing I would add is a test which checks that assert grp.getgrgid(...)[0] == grp.getgrgid(...).gr_name (and others). I didn't check, maybe it's already there.

test_pwd and test_grp already implement these checks.

Also, while you're there, perhaps you want to also make the replacement in other places? Like Lib/http/server.py (grep for getpwuid, getgrgid, and others under Lib/ to find all).

Oh right, I missed some code. I updated the PR to replace more code.

@giampaolo: Would you mind to review the updated PR?

@read-the-docs-community

Copy link
Copy Markdown

Documentation build overview

📚 cpython-previews | 🛠️ Build #33966189 | 📁 Comparing d85a43d against main (115400b)

  🔍 Preview build  

1 file changed
± library/os.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants