Skip to content

bpo-32731: Specify Exception type of getpass.getuser #5616

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions Doc/library/getpass.rst
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,10 @@ The :mod:`getpass` module provides two functions:

This function checks the environment variables :envvar:`LOGNAME`,
:envvar:`USER`, :envvar:`LNAME` and :envvar:`USERNAME`, in order, and
returns the value of the first one which is set to a non-empty string. If
none are set, the login name from the password database is returned on
systems which support the :mod:`pwd` module, otherwise, an exception is
raised.
returns the value of the first one which is set to a non-empty string.
If none are set, the function attempts to retrieve the login name from the
password database. On systems which the :mod:`pwd` module is not supported,
an :exc:`ImportError` is raised. If no login name is found, an
:exc:`KeyError` is raised :func:`pwd.getpwuid`.
Copy link
Member

Choose a reason for hiding this comment

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

What is the mention for pwd.getwuid() for? Is it to state that it's the function that causes KeyError to be raised?

And are there tests that these exception are raised in these scenarios?


In general, this function should be preferred over :func:`os.getlogin()`.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Improve documentation of exception raised in :func:`getpass.getuser()`
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Improve documentation of exception raised in :func:`getpass.getuser()`
Improve documentation of exceptions raised in :func:`getpass.getuser()`.