Catch `OSError` from `getpass.getuser()` (#11875)
- 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`. Fixes #11874
This commit is contained in:
parent
8853a57532
commit
14d3707818
1
AUTHORS
1
AUTHORS
|
@ -340,6 +340,7 @@ Ronny Pfannschmidt
|
||||||
Ross Lawley
|
Ross Lawley
|
||||||
Ruaridh Williamson
|
Ruaridh Williamson
|
||||||
Russel Winder
|
Russel Winder
|
||||||
|
Russell Martin
|
||||||
Ryan Puddephatt
|
Ryan Puddephatt
|
||||||
Ryan Wooden
|
Ryan Wooden
|
||||||
Sadra Barikbin
|
Sadra Barikbin
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Correctly handle errors from :func:`getpass.getuser` in Python 3.13.
|
|
@ -204,7 +204,7 @@ def get_user() -> Optional[str]:
|
||||||
import getpass
|
import getpass
|
||||||
|
|
||||||
return getpass.getuser()
|
return getpass.getuser()
|
||||||
except (ImportError, KeyError):
|
except (ImportError, OSError, KeyError):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue