Catch `OSError` from `getpass.getuser()`

- Previously, `getpass.getuser()` would leak an ImportError if the
  USERNAME environment variable was not set on Windows because the `pwd`
  module cannot be imported.
- Starting in Python 3.13.0a3, it only raises `OSError`.
This commit is contained in:
Russell Martin 2024-01-28 17:31:37 -05:00
parent 8853a57532
commit e5584da625
No known key found for this signature in database
GPG Key ID: FE407B9181ED253E
2 changed files with 2 additions and 1 deletions

View File

@ -340,6 +340,7 @@ Ronny Pfannschmidt
Ross Lawley
Ruaridh Williamson
Russel Winder
Russell Martin
Ryan Puddephatt
Ryan Wooden
Sadra Barikbin

View File

@ -204,7 +204,7 @@ def get_user() -> Optional[str]:
import getpass
return getpass.getuser()
except (ImportError, KeyError):
except (ImportError, OSError, KeyError):
return None