]> granicus.if.org Git - python/commitdiff
bpo-32651 Recommend getpass.getuser() (GH-5301) (#5304)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Wed, 24 Jan 2018 19:09:56 +0000 (11:09 -0800)
committerBarry Warsaw <barry@python.org>
Wed, 24 Jan 2018 19:09:56 +0000 (14:09 -0500)
* bpo-32651 - In the documentation for os.getlogin(), recommend getpass.getuser()
(cherry picked from commit d499031f5f33c3ef71be7c81ef52eee6b47c42e1)

Doc/library/getpass.rst
Doc/library/os.rst

index 5eb9f04a8da795332cf0d6b8ba77e42558187c09..82b11919a3d2bf67eeb7ef40e80d51b93f96a4bb 100644 (file)
@@ -42,8 +42,10 @@ The :mod:`getpass` module provides two functions:
    Return the "login name" of the user.
 
    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.
+   :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.
 
+   In general, this function should be preferred over :func:`os.getlogin()`.
index 974ab2d481e21070c4c6b5f36fca398e7a1e42ef..b2722168bc213841b638e2f8c82e4b50a5370cf6 100644 (file)
@@ -325,10 +325,11 @@ process and user.
 .. function:: getlogin()
 
    Return the name of the user logged in on the controlling terminal of the
-   process.  For most purposes, it is more useful to use the environment
-   variables :envvar:`LOGNAME` or :envvar:`USERNAME` to find out who the user
-   is, or ``pwd.getpwuid(os.getuid())[0]`` to get the login name of the current
-   real user id.
+   process.  For most purposes, it is more useful to use
+   :func:`getpass.getuser` since the latter checks the environment variables
+   :envvar:`LOGNAME` or :envvar:`USERNAME` to find out who the user is, and
+   falls back to ``pwd.getpwuid(os.getuid())[0]`` to get the login name of the
+   current real user id.
 
    Availability: Unix, Windows.