8000 Split up exception handling in resolve() for greater clarity. · python/cpython@df04357 · GitHub
[go: up one dir, main page]

Skip to content

Commit df04357

Browse files
committed
Split up exception handling in resolve() for greater clarity.
1 parent 72147c5 commit df04357

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

Lib/pathlib.py

Expand all lines: Lib/pathlib.py
Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1056,20 +1056,25 @@ def resolve(self, strict=False):
10561056
Windows).
10571057
"""
10581058

1059+
def check_eloop(e):
1060+
winerror = getattr(e, 'winerror', 0)
1061+
if e.errno == ELOOP or winerror == _WINERROR_CANT_RESOLVE_FILENAME:
1062+
raise RuntimeError("Symlink loop from %r" % e.filename)
1063+
10591064
try:
10601065
s = self._accessor.realpath(self, strict=strict)
1061-
p = self._from_parts((s,))
1066+
except OSError as e:
1067+
check_eloop(e)
1068+
raise
1069+
p = self._from_parts((s,))
10621070

1063-
# In non-strict mode, realpath() doesn't raise on symlink loops.
1064-
# Ensure we get an exception by calling stat()
1065-
if not strict:
1071+
# In non-strict mode, realpath() doesn't raise on symlink loops.
1072+
# Ensure we get an exception by calling stat()
1073+
if not strict:
1074+
try:
10661075
p.stat()
1067-
except OSError as ex:
1068-
winerror = getattr(ex, 'winerror', 0)
1069-
if ex.errno == ELOOP or winerror == _WINERROR_CANT_RESOLVE_FILENAME:
1070-
raise RuntimeError("Symlink loop from %r", ex.filename)
1071-
if strict:
1072-
raise
1076+
except OSError as e:
1077+
check_eloop(e)
10731078
return p
10741079

10751080
def stat(self, *, follow_symlinks=True):

0 commit comments

Comments
 (0)
0