8000 Split try except blocks · python/cpython@de4b09e · GitHub
[go: up one dir, main page]

Skip to content

Commit de4b09e

Browse files
committed
Split try except blocks
1 parent 9520cc6 commit de4b09e

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

Lib/posixpath.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -236,9 +236,12 @@ def expanduser(path):
236236
if 'HOME' not in os.environ:
237237
try:
238238
import pwd
239-
userhome = pwd.getpwuid(os.getuid()).pw_dir
240-
except (ImportError, KeyError):
239+
except ImportError:
241240
# pwd module unavailable, return path unchanged
241+
return path
242+
try:
243+
userhome = pwd.getpwuid(os.getuid()).pw_dir
244+
except KeyError:
242245
# bpo-10496: if the current user identifier doesn't exist in the
243246
# password database, return the path unchanged
244247
return path
@@ -247,12 +250,15 @@ def expanduser(path):
247250
else:
248251
try:
249252
import pwd
250-
name = path[1:i]
251-
if isinstance(name, bytes):
252-
name = name.decode('ascii')
253-
userhome = pwd.getpwnam(name).pw_dir
254-
except (ImportError, KeyError):
253+
except ImportError:
255254
# pwd module unavailable, return path unchanged
255+
return path
256+
name = path[1:i]
257+
if isinstance(name, bytes):
258+
name = name.decode('ascii')
259+
try:
260+
userhome = pwd.getpwnam(name).pw_dir
261+
except KeyError:
256262
# bpo-10496: if the user name from the path doesn't exist in the
257263
# password database, return the path unchanged
258264
return path

0 commit comments

Comments
 (0)
0