From 0076ca48e9cd116bb9d283d014fe69a72c9f1f6f Mon Sep 17 00:00:00 2001 From: "Miss Islington (bot)" <31488909+miss-islington@users.noreply.github.com> Date: Wed, 30 Nov 2022 15:31:49 -0800 Subject: [PATCH] gh-96192: fix os.ismount() to use a path that is str or bytes (GH-96194) (cherry picked from commit 367f552129341796d75fc4cc40edb49405235a2b) Co-authored-by: Christoph Anton Mitterer Signed-off-by: Christoph Anton Mitterer Co-authored-by: Eryk Sun Co-authored-by: Jelle Zijlstra --- Lib/posixpath.py | 1 + Lib/test/test_posixpath.py | 2 ++ .../next/Library/2022-08-23-03-13-18.gh-issue-96192.TJywOF.rst | 1 + 3 files changed, 4 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2022-08-23-03-13-18.gh-issue-96192.TJywOF.rst diff --git a/Lib/posixpath.py b/Lib/posixpath.py index 5e1ebe3293d..5b4d78bca06 100644 --- a/Lib/posixpath.py +++ b/Lib/posixpath.py @@ -195,6 +195,7 @@ def ismount(path): if stat.S_ISLNK(s1.st_mode): return False + path = os.fspath(path) if isinstance(path, bytes): parent = join(path, b'..') else: diff --git a/Lib/test/test_posixpath.py b/Lib/test/test_posixpath.py index c644f881e46..8a1dd131928 100644 --- a/Lib/test/test_posixpath.py +++ b/Lib/test/test_posixpath.py @@ -178,6 +178,8 @@ class PosixPathTest(unittest.TestCase): def test_ismount(self): self.assertIs(posixpath.ismount("/"), True) self.assertIs(posixpath.ismount(b"/"), True) + self.assertIs(posixpath.ismount(FakePath("/")), True) + self.assertIs(posixpath.ismount(FakePath(b"/")), True) def test_ismount_non_existent(self): # Non-existent mountpoint. diff --git a/Misc/NEWS.d/next/Library/2022-08-23-03-13-18.gh-issue-96192.TJywOF.rst b/Misc/NEWS.d/next/Library/2022-08-23-03-13-18.gh-issue-96192.TJywOF.rst new file mode 100644 index 00000000000..58e51da6ba3 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2022-08-23-03-13-18.gh-issue-96192.TJywOF.rst @@ -0,0 +1 @@ +Fix handling of ``bytes`` :term:`path-like objects ` in :func:`os.ismount()`.