From 13d10dfcb5800fdd676a8ddd47395578b765a2c0 Mon Sep 17 00:00:00 2001 From: Amin Alaee Date: Sat, 23 Sep 2023 14:14:06 +0200 Subject: [PATCH 1/3] gh-109782 Update NT os.path.isdir signature --- Modules/clinic/posixmodule.c.h | 16 ++++++++-------- Modules/posixmodule.c | 10 +++++----- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/Modules/clinic/posixmodule.c.h b/Modules/clinic/posixmodule.c.h index c3e7f86b3e33f1..e77a31b947f45e 100644 --- a/Modules/clinic/posixmodule.c.h +++ b/Modules/clinic/posixmodule.c.h @@ -1977,7 +1977,7 @@ os__path_splitroot(PyObject *module, PyObject *const *args, Py_ssize_t nargs, Py #if defined(MS_WINDOWS) PyDoc_STRVAR(os__path_isdir__doc__, -"_path_isdir($module, /, path)\n" +"_path_isdir($module, /, s)\n" "--\n" "\n" "Return true if the pathname refers to an existing directory."); @@ -1986,7 +1986,7 @@ PyDoc_STRVAR(os__path_isdir__doc__, {"_path_isdir", _PyCFunction_CAST(os__path_isdir), METH_FASTCALL|METH_KEYWORDS, os__path_isdir__doc__}, static PyObject * -os__path_isdir_impl(PyObject *module, PyObject *path); +os__path_isdir_impl(PyObject *module, PyObject *s); static PyObject * os__path_isdir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) @@ -2001,7 +2001,7 @@ os__path_isdir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObje PyObject *ob_item[NUM_KEYWORDS]; } _kwtuple = { .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) - .ob_item = { &_Py_ID(path), }, + .ob_item = { &_Py_ID(s), }, }; #undef NUM_KEYWORDS #define KWTUPLE (&_kwtuple.ob_base.ob_base) @@ -2010,7 +2010,7 @@ os__path_isdir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObje # define KWTUPLE NULL #endif // !Py_BUILD_CORE - static const char * const _keywords[] = {"path", NULL}; + static const char * const _keywords[] = {"s", NULL}; static _PyArg_Parser _parser = { .keywords = _keywords, .fname = "_path_isdir", @@ -2018,14 +2018,14 @@ os__path_isdir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObje }; #undef KWTUPLE PyObject *argsbuf[1]; - PyObject *path; + PyObject *s; args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); if (!args) { goto exit; } - path = args[0]; - return_value = os__path_isdir_impl(module, path); + s = args[0]; + return_value = os__path_isdir_impl(module, s); exit: return return_value; @@ -11988,4 +11988,4 @@ os_waitstatus_to_exitcode(PyObject *module, PyObject *const *args, Py_ssize_t na #ifndef OS_WAITSTATUS_TO_EXITCODE_METHODDEF #define OS_WAITSTATUS_TO_EXITCODE_METHODDEF #endif /* !defined(OS_WAITSTATUS_TO_EXITCODE_METHODDEF) */ -/*[clinic end generated code: output=1dd5aa7495cd6e3a input=a9049054013a1b77]*/ +/*[clinic end generated code: output=51aa26bc6a41e1da input=a9049054013a1b77]*/ diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index 096aa043514c85..abf449e25493fa 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -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(); From 2e995911d9d46af1b3fd31734a0311b645da96d5 Mon Sep 17 00:00:00 2001 From: AlexWaygood Date: Sun, 24 Sep 2023 16:44:03 +0100 Subject: [PATCH 2/3] Add news and tests --- Lib/test/test_ntpath.py | 11 +++++++++++ .../2023-09-24-16-43-33.gh-issue-109782.gMC_7z.rst | 2 ++ 2 files changed, 13 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2023-09-24-16-43-33.gh-issue-109782.gMC_7z.rst diff --git a/Lib/test/test_ntpath.py b/Lib/test/test_ntpath.py index d91dcdfb0c5fac..92108878a923e6 100644 --- a/Lib/test/test_ntpath.py +++ b/Lib/test/test_ntpath.py @@ -1,4 +1,5 @@ import inspect +import genericpath import ntpath import os import string @@ -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 diff --git a/Misc/NEWS.d/next/Library/2023-09-24-16-43-33.gh-issue-109782.gMC_7z.rst b/Misc/NEWS.d/next/Library/2023-09-24-16-43-33.gh-issue-109782.gMC_7z.rst new file mode 100644 index 00000000000000..7612e59dc45412 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2023-09-24-16-43-33.gh-issue-109782.gMC_7z.rst @@ -0,0 +1,2 @@ +Ensure the signature of :func:`os.path.isdir` is identical on all platforms. +Patch by Amin Alaee. From 9cc53cda6c593811fabd9e2f71f439b4068d782f Mon Sep 17 00:00:00 2001 From: Amin Alaee Date: Thu, 28 Sep 2023 09:28:24 +0200 Subject: [PATCH 3/3] Remove test --- Lib/test/test_ntpath.py | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/Lib/test/test_ntpath.py b/Lib/test/test_ntpath.py index 92108878a923e6..d91dcdfb0c5fac 100644 --- a/Lib/test/test_ntpath.py +++ b/Lib/test/test_ntpath.py @@ -1,5 +1,4 @@ import inspect -import genericpath import ntpath import os import string @@ -999,16 +998,6 @@ 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