Skip to content

Commit 4ab19f9

Browse files
[3.12] gh-124917: Allow keyword args to os.path.exists/lexists on Windows (GH-124918) (#125334)
(cherry picked from commit cc2938a)
1 parent 5903631 commit 4ab19f9

File tree

4 files changed

+43
-7
lines changed

4 files changed

+43
-7
lines changed

Lib/test/test_genericpath.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,11 @@ def test_exists(self):
158158
self.assertIs(self.pathmodule.lexists(filename + '\x00'), False)
159159
self.assertIs(self.pathmodule.lexists(bfilename + b'\x00'), False)
160160

161+
# Keyword arguments are accepted
162+
self.assertIs(self.pathmodule.exists(path=filename), True)
163+
if self.pathmodule is not genericpath:
164+
self.assertIs(self.pathmodule.lexists(path=filename), True)
165+
161166
@unittest.skipUnless(hasattr(os, "pipe"), "requires os.pipe()")
162167
@unittest.skipIf(is_emscripten, "Emscripten pipe fds have no stat")
163168
def test_exists_fd(self):
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Allow calling :func:`os.path.exists` and :func:`os.path.lexists` with
2+
keyword arguments on Windows. Fixes a regression in 3.12.4.

Modules/clinic/posixmodule.c.h

Lines changed: 35 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Modules/posixmodule.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5209,15 +5209,14 @@ _testFileType(path_t *path, int testedType)
52095209
os._path_exists -> bool
52105210
52115211
path: path_t(allow_fd=True, suppress_value_error=True)
5212-
/
52135212
52145213
Test whether a path exists. Returns False for broken symbolic links.
52155214
52165215
[clinic start generated code]*/
52175216

52185217
static int
52195218
os__path_exists_impl(PyObject *module, path_t *path)
5220-
/*[clinic end generated code: output=8da13acf666e16ba input=29198507a6082a57]*/
5219+
/*[clinic end generated code: output=8da13acf666e16ba input=142beabfc66783eb]*/
52215220
{
52225221
return _testFileExists(path, TRUE);
52235222
}

0 commit comments

Comments
 (0)