Mailing List Archive

gh-117394: Speed up os.path.ismount() on Posix (GH-117447)
https://github.com/python/cpython/commit/4e502a4997af4c8042a6ac13115a3f8ba31520ea
commit: 4e502a4997af4c8042a6ac13115a3f8ba31520ea
branch: main
author: Serhiy Storchaka <storchaka@gmail.com>
committer: serhiy-storchaka <storchaka@gmail.com>
date: 2024-04-17T12:58:19+03:00
summary:

gh-117394: Speed up os.path.ismount() on Posix (GH-117447)

It is now 2-3 times faster if the user has permissions.

files:
A Misc/NEWS.d/next/Library/2024-04-02-11-17-44.gh-issue-117394.2aoSlb.rst
M Lib/posixpath.py

diff --git a/Lib/posixpath.py b/Lib/posixpath.py
index 11cbaca53edb12..79cda50753e0d2 100644
--- a/Lib/posixpath.py
+++ b/Lib/posixpath.py
@@ -206,11 +206,14 @@ def ismount(path):
parent = join(path, b'..')
else:
parent = join(path, '..')
- parent = realpath(parent)
try:
s2 = os.lstat(parent)
- except (OSError, ValueError):
- return False
+ except OSError:
+ parent = realpath(parent)
+ try:
+ s2 = os.lstat(parent)
+ except OSError:
+ return False

# path/.. on a different device as path or the same i-node as path
return s1.st_dev != s2.st_dev or s1.st_ino == s2.st_ino
diff --git a/Misc/NEWS.d/next/Library/2024-04-02-11-17-44.gh-issue-117394.2aoSlb.rst b/Misc/NEWS.d/next/Library/2024-04-02-11-17-44.gh-issue-117394.2aoSlb.rst
new file mode 100644
index 00000000000000..7b695be4b35d0c
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2024-04-02-11-17-44.gh-issue-117394.2aoSlb.rst
@@ -0,0 +1 @@
+:func:`os.path.ismount` is now 2-3 times faster if the user has permissions.

_______________________________________________
Python-checkins mailing list -- python-checkins@python.org
To unsubscribe send an email to python-checkins-leave@python.org
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: list-python-checkins@lists.gossamer-threads.com