Author gregory.p.smith
Recipients gregory.p.smith
Date 2018-01-31.18:02:31
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1517421752.06.0.467229070634.issue32731@psf.upfronthosting.co.za>
In-reply-to
Content
This has been true since Python 1.x.  getpass.getuser() is documented as "raising an exception" but doesn't specify what exception.

On Windows when the environment variables it looks at are not set, an ImportError (!) escapes due to "import pwd" failing.  It could just a easily allow an exception from the following pwd.getpwuid(os.getuid())[0] call to escape on systems when pwd exists.

None of these are actually helpful to the caller as they are left having to catch a bare Exception around a getpass.getuser() call to take another course of action.  I filed this as I just saw someone suggesting code that specifically catches ImportError on getpass.getuser().

It is too late to change the exception type coming out in 2.7 or 3.6, but cleaning up this underspecified behavior to be a meaningful exception for 3.7 seems reasonable.
History
Date User Action Args
2018-01-31 18:02:32gregory.p.smithsetrecipients: + gregory.p.smith
2018-01-31 18:02:32gregory.p.smithsetmessageid: <1517421752.06.0.467229070634.issue32731@psf.upfronthosting.co.za>
2018-01-31 18:02:31gregory.p.smithlinkissue32731 messages
2018-01-31 18:02:31gregory.p.smithcreate