Skip to content

gh-109782: Ensure os.path.isdir has the same signature on all platforms #109790

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 28, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions Lib/test/test_ntpath.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import inspect
import genericpath
import ntpath
import os
import string
Expand Down Expand Up @@ -998,6 +999,16 @@ def test_fast_paths_in_use(self):
self.assertTrue(os.path.exists is nt._path_exists)
self.assertFalse(inspect.isfunction(os.path.exists))

def test_signatures_identical_to_other_platforms(self):
for func_name in "isdir", "isfile", "islink", "exists":
with self.subTest(func_name=func_name):
ntpath_function = getattr(ntpath, func_name)
genericpath_function = getattr(genericpath, func_name)
self.assertEqual(
inspect.signature(ntpath_function),
inspect.signature(genericpath_function)
)

@unittest.skipIf(os.name != 'nt', "Dev Drives only exist on Win32")
def test_isdevdrive(self):
# Result may be True or False, but shouldn't raise
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Ensure the signature of :func:`os.path.isdir` is identical on all platforms.
Patch by Amin Alaee.
16 changes: 8 additions & 8 deletions Modules/clinic/posixmodule.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions Modules/posixmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -4912,25 +4912,25 @@ os__path_splitroot_impl(PyObject *module, path_t *path)
/*[clinic input]
os._path_isdir

path: 'O'
s: 'O'

Return true if the pathname refers to an existing directory.

[clinic start generated code]*/

static PyObject *
os__path_isdir_impl(PyObject *module, PyObject *path)
/*[clinic end generated code: output=00faea0af309669d input=b1d2571cf7291aaf]*/
os__path_isdir_impl(PyObject *module, PyObject *s)
/*[clinic end generated code: output=9d87ab3c8b8a4e61 input=c17f7ef21d22d64e]*/
{
HANDLE hfile;
BOOL close_file = TRUE;
FILE_BASIC_INFO info;
path_t _path = PATH_T_INITIALIZE("isdir", "path", 0, 1);
path_t _path = PATH_T_INITIALIZE("isdir", "s", 0, 1);
int result;
BOOL slow_path = TRUE;
FILE_STAT_BASIC_INFORMATION statInfo;

if (!path_converter(path, &_path)) {
if (!path_converter(s, &_path)) {
path_cleanup(&_path);
if (PyErr_ExceptionMatches(PyExc_ValueError)) {
PyErr_Clear();
Expand Down