Bug report
Bug description:
Two closely-related issues in pathlib.Path.resolve():
First, resolve(strict=True) raises RuntimeError rather than OSError when a symlink loop is encountered. This is done only for backwards compatibility, since #25264 made pathlib call os.path.realpath(). It should raise OSError(ELOOP)
Second, resolve(strict=False) suppresses every kind of OS error except symlink loop errors. Again this is only for backwards compatibility. It should suppress exceptions about symlink loops.
Relevant code:
|
def check_eloop(e): |
|
winerror = getattr(e, 'winerror', 0) |
|
if e.errno == ELOOP or winerror == _WINERROR_CANT_RESOLVE_FILENAME: |
|
raise RuntimeError("Symlink loop from %r" % e.filename) |
|
|
|
try: |
|
s = os.path.realpath(self, strict=strict) |
|
except OSError as e: |
|
check_eloop(e) |
|
raise |
|
p = self.with_segments(s) |
|
|
|
# In non-strict mode, realpath() doesn't raise on symlink loops. |
|
# Ensure we get an exception by calling stat() |
|
if not strict: |
|
try: |
|
p.stat() |
|
except OSError as e: |
|
check_eloop(e) |
|
return p |
CPython versions tested on:
3.11, 3.12, CPython main branch
Operating systems tested on:
No response
Linked PRs
Bug report
Bug description:
Two closely-related issues in
pathlib.Path.resolve():First,
resolve(strict=True)raisesRuntimeErrorrather thanOSErrorwhen a symlink loop is encountered. This is done only for backwards compatibility, since #25264 made pathlib callos.path.realpath(). It should raiseOSError(ELOOP)Second,
resolve(strict=False)suppresses every kind of OS error except symlink loop errors. Again this is only for backwards compatibility. It should suppress exceptions about symlink loops.Relevant code:
cpython/Lib/pathlib.py
Lines 1233 to 1252 in e21c89f
CPython versions tested on:
3.11, 3.12, CPython main branch
Operating systems tested on:
No response
Linked PRs
pathlib.Path.resolve()#109192