fix: move 'import getpass' statement to try-clause
This commit is contained in:
parent
1ea7081752
commit
988197c795
|
@ -158,9 +158,9 @@ class TempPathFactory:
|
||||||
def get_user() -> Optional[str]:
|
def get_user() -> Optional[str]:
|
||||||
"""Return the current user name, or None if getuser() does not work
|
"""Return the current user name, or None if getuser() does not work
|
||||||
in the current environment (see #1010)."""
|
in the current environment (see #1010)."""
|
||||||
import getpass
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
# In some exotic environments, getpass may not be importable.
|
||||||
|
import getpass
|
||||||
return getpass.getuser()
|
return getpass.getuser()
|
||||||
except (ImportError, KeyError):
|
except (ImportError, KeyError):
|
||||||
return None
|
return None
|
||||||
|
|
Loading…
Reference in New Issue