-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
Closed as not planned
Labels
stdlibPython modules in the Lib dirPython modules in the Lib dirtype-featureA feature request or enhancementA feature request or enhancement
Description
Feature or enhancement
Proposal:
glob
currently needs its own implementation of os.path.lexists()
& os.path.isdir()
to support dir_fd
:
Lines 201 to 222 in f74e512
def _lexists(pathname, dir_fd): | |
# Same as os.path.lexists(), but with dir_fd | |
if dir_fd is None: | |
return os.path.lexists(pathname) | |
try: | |
os.lstat(pathname, dir_fd=dir_fd) | |
except (OSError, ValueError): | |
return False | |
else: | |
return True | |
def _isdir(pathname, dir_fd): | |
# Same as os.path.isdir(), but with dir_fd | |
if dir_fd is None: | |
return os.path.isdir(pathname) | |
try: | |
st = os.stat(pathname, dir_fd=dir_fd) | |
except (OSError, ValueError): | |
return False | |
else: | |
return stat.S_ISDIR(st.st_mode) | |
We could refactor this by adding dir_fd
to os.path.lexists()
& os.path.isdir()
:
-def lexists(path):
+def lexists(path, *, dir_fd: int | None = None):
"""Test whether a path exists. Returns True for broken symbolic links"""
try:
- os.lstat(path)
+ os.lstat(path, dir_fd=dir_fd)
except (OSError, ValueError):
return False
return True
-def isdir(s):
+def isdir(s, *, dir_fd: int | None = None):
"""Return true if the pathname refers to an existing directory."""
try:
- st = os.stat(s)
+ st = os.stat(s, dir_fd=dir_fd)
except (OSError, ValueError):
return False
return stat.S_ISDIR(st.st_mode)
Note: nt._path_isdir()
(& nt._path_lexists()
when #117842 lands) need to raise an error for this.
Has this already been discussed elsewhere?
This is a minor feature, which does not need previous discussion elsewhere
Links to previous discussion of this feature:
No response
Metadata
Metadata
Assignees
Labels
stdlibPython modules in the Lib dirPython modules in the Lib dirtype-featureA feature request or enhancementA feature request or enhancement