Skip to content

Commit 0821923

Browse files
authored
gh-117114: Make os.path.isdevdrive available on all platforms (GH-117115)
1 parent c227617 commit 0821923

File tree

5 files changed

+39
-57
lines changed

5 files changed

+39
-57
lines changed

Doc/library/os.path.rst

+4-13
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
.. module:: os.path
55
:synopsis: Operations on pathnames.
66

7-
**Source code:** :source:`Lib/posixpath.py` (for POSIX) and
7+
**Source code:** :source:`Lib/genericpath.py`, :source:`Lib/posixpath.py` (for POSIX) and
88
:source:`Lib/ntpath.py` (for Windows).
99

1010
.. index:: single: path; operations
@@ -85,8 +85,6 @@ the :mod:`glob` module.)
8585
if *paths* is empty. Unlike :func:`commonprefix`, this returns a
8686
valid path.
8787

88-
.. availability:: Unix, Windows.
89-
9088
.. versionadded:: 3.5
9189

9290
.. versionchanged:: 3.6
@@ -324,10 +322,11 @@ the :mod:`glob` module.)
324322
Dev Drives. See `the Windows documentation <https://learn.microsoft.com/windows/dev-drive/>`_
325323
for information on enabling and creating Dev Drives.
326324

327-
.. availability:: Windows.
328-
329325
.. versionadded:: 3.12
330326

327+
.. versionchanged:: 3.13
328+
The function is now available on all platforms, and will always return ``False`` on those that have no support for Dev Drives
329+
331330

332331
.. function:: isreserved(path)
333332

@@ -442,8 +441,6 @@ the :mod:`glob` module.)
442441

443442
*start* defaults to :data:`os.curdir`.
444443

445-
.. availability:: Unix, Windows.
446-
447444
.. versionchanged:: 3.6
448445
Accepts a :term:`path-like object`.
449446

@@ -454,8 +451,6 @@ the :mod:`glob` module.)
454451
This is determined by the device number and i-node number and raises an
455452
exception if an :func:`os.stat` call on either pathname fails.
456453

457-
.. availability:: Unix, Windows.
458-
459454
.. versionchanged:: 3.2
460455
Added Windows support.
461456

@@ -470,8 +465,6 @@ the :mod:`glob` module.)
470465

471466
Return ``True`` if the file descriptors *fp1* and *fp2* refer to the same file.
472467

473-
.. availability:: Unix, Windows.
474-
475468
.. versionchanged:: 3.2
476469
Added Windows support.
477470

@@ -486,8 +479,6 @@ the :mod:`glob` module.)
486479
:func:`os.lstat`, or :func:`os.stat`. This function implements the
487480
underlying comparison used by :func:`samefile` and :func:`sameopenfile`.
488481

489-
.. availability:: Unix, Windows.
490-
491482
.. versionchanged:: 3.4
492483
Added Windows support.
493484

Lib/genericpath.py

+26-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
import stat
88

99
__all__ = ['commonprefix', 'exists', 'getatime', 'getctime', 'getmtime',
10-
'getsize', 'isdir', 'isfile', 'islink', 'samefile', 'sameopenfile',
11-
'samestat']
10+
'getsize', 'isdevdrive', 'isdir', 'isfile', 'isjunction', 'islink',
11+
'lexists', 'samefile', 'sameopenfile', 'samestat']
1212

1313

1414
# Does a path exist?
@@ -22,6 +22,15 @@ def exists(path):
2222
return True
2323

2424

25+
# Being true for dangling symbolic links is also useful.
26+
def lexists(path):
27+
"""Test whether a path exists. Returns True for broken symbolic links"""
28+
try:
29+
os.lstat(path)
30+
except (OSError, ValueError):
31+
return False
32+
return True
33+
2534
# This follows symbolic links, so both islink() and isdir() can be true
2635
# for the same path on systems that support symlinks
2736
def isfile(path):
@@ -57,6 +66,21 @@ def islink(path):
5766
return stat.S_ISLNK(st.st_mode)
5867

5968

69+
# Is a path a junction?
70+
def isjunction(path):
71+
"""Test whether a path is a junction
72+
Junctions are not supported on the current platform"""
73+
os.fspath(path)
74+
return False
75+
76+
77+
def isdevdrive(path):
78+
"""Determines whether the specified path is on a Windows Dev Drive.
79+
Dev Drives are not supported on the current platform"""
80+
os.fspath(path)
81+
return False
82+
83+
6084
def getsize(filename):
6185
"""Return the size of a file, reported by os.stat()."""
6286
return os.stat(filename).st_size

Lib/ntpath.py

+7-21
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
"ismount","isreserved","expanduser","expandvars","normpath",
3030
"abspath","curdir","pardir","sep","pathsep","defpath","altsep",
3131
"extsep","devnull","realpath","supports_unicode_filenames","relpath",
32-
"samefile", "sameopenfile", "samestat", "commonpath", "isjunction"]
32+
"samefile", "sameopenfile", "samestat", "commonpath", "isjunction",
33+
"isdevdrive"]
3334

3435
def _get_bothseps(path):
3536
if isinstance(path, bytes):
@@ -280,21 +281,9 @@ def isjunction(path):
280281
return False
281282
return bool(st.st_reparse_tag == stat.IO_REPARSE_TAG_MOUNT_POINT)
282283
else:
283-
def isjunction(path):
284-
"""Test whether a path is a junction"""
285-
os.fspath(path)
286-
return False
287-
288-
289-
# Being true for dangling symbolic links is also useful.
284+
# Use genericpath.isjunction as imported above
285+
pass
290286

291-
def lexists(path):
292-
"""Test whether a path exists. Returns True for broken symbolic links"""
293-
try:
294-
st = os.lstat(path)
295-
except (OSError, ValueError):
296-
return False
297-
return True
298287

299288
# Is a path a mount point?
300289
# Any drive letter root (eg c:\)
@@ -916,15 +905,12 @@ def commonpath(paths):
916905

917906
try:
918907
from nt import _path_isdevdrive
919-
except ImportError:
920-
def isdevdrive(path):
921-
"""Determines whether the specified path is on a Windows Dev Drive."""
922-
# Never a Dev Drive
923-
return False
924-
else:
925908
def isdevdrive(path):
926909
"""Determines whether the specified path is on a Windows Dev Drive."""
927910
try:
928911
return _path_isdevdrive(abspath(path))
929912
except OSError:
930913
return False
914+
except ImportError:
915+
# Use genericpath.isdevdrive as imported above
916+
pass

Lib/posixpath.py

+1-21
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
"samefile","sameopenfile","samestat",
3636
"curdir","pardir","sep","pathsep","defpath","altsep","extsep",
3737
"devnull","realpath","supports_unicode_filenames","relpath",
38-
"commonpath", "isjunction"]
38+
"commonpath", "isjunction","isdevdrive"]
3939

4040

4141
def _get_sep(path):
@@ -187,26 +187,6 @@ def dirname(p):
187187
return head
188188

189189

190-
# Is a path a junction?
191-
192-
def isjunction(path):
193-
"""Test whether a path is a junction
194-
Junctions are not a part of posix semantics"""
195-
os.fspath(path)
196-
return False
197-
198-
199-
# Being true for dangling symbolic links is also useful.
200-
201-
def lexists(path):
202-
"""Test whether a path exists. Returns True for broken symbolic links"""
203-
try:
204-
os.lstat(path)
205-
except (OSError, ValueError):
206-
return False
207-
return True
208-
209-
210190
# Is a path a mount point?
211191
# (Does this work for all UNIXes? Is it even guaranteed to work by Posix?)
212192

Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Make :func:`os.path.isdevdrive` available on all platforms. For those that do not offer Dev Drives, it will always return ``False``.

0 commit comments

Comments
 (0)