Skip to content

Commit b942707

Browse files
BNMetricspablogsal
authored andcommitted
bpo-29341: Clarify that path-like objects are accepted in some os methods (GH-10101)
Some methods in the os module can accept path-like objects. This is documented in the general documentation but not in the function docstrings. To keep both in sync, the docstrings need to be updated to reflect that path-like objects are also accepted.
1 parent 488c0a6 commit b942707

File tree

3 files changed

+33
-31
lines changed

3 files changed

+33
-31
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Clarify in the docstrings of :mod:`os` methods that path-like objects are also accepted
2+
as input parameters.

Modules/clinic/posixmodule.c.h

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

Modules/posixmodule.c

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2480,7 +2480,7 @@ class sched_param_converter(CConverter):
24802480
os.stat
24812481
24822482
path : path_t(allow_fd=True)
2483-
Path to be examined; can be string, bytes, path-like object or
2483+
Path to be examined; can be string, bytes, a path-like object or
24842484
open-file-descriptor int.
24852485
24862486
*
@@ -2508,7 +2508,7 @@ It's an error to use dir_fd or follow_symlinks when specifying path as
25082508

25092509
static PyObject *
25102510
os_stat_impl(PyObject *module, path_t *path, int dir_fd, int follow_symlinks)
2511-
/*[clinic end generated code: output=7d4976e6f18a59c5 input=270bd64e7bb3c8f7]*/
2511+
/*[clinic end generated code: output=7d4976e6f18a59c5 input=01d362ebcc06996b]*/
25122512
{
25132513
return posix_do_stat("stat", path, dir_fd, follow_symlinks);
25142514
}
@@ -2542,7 +2542,7 @@ os_lstat_impl(PyObject *module, path_t *path, int dir_fd)
25422542
os.access -> bool
25432543
25442544
path: path_t
2545-
Path to be tested; can be string or bytes
2545+
Path to be tested; can be string, bytes, or a path-like object.
25462546
25472547
mode: int
25482548
Operating-system mode bitfield. Can be F_OK to test existence,
@@ -2580,7 +2580,7 @@ Note that most operations will use the effective uid/gid, therefore this
25802580
static int
25812581
os_access_impl(PyObject *module, path_t *path, int mode, int dir_fd,
25822582
int effective_ids, int follow_symlinks)
2583-
/*[clinic end generated code: output=cf84158bc90b1a77 input=8e8c3a6ba791fee3]*/
2583+
/*[clinic end generated code: output=cf84158bc90b1a77 input=3ffe4e650ee3bf20]*/
25842584
{
25852585
int return_value;
25862586

@@ -2772,7 +2772,7 @@ os_fchdir_impl(PyObject *module, int fd)
27722772
os.chmod
27732773
27742774
path: path_t(allow_fd='PATH_HAVE_FCHMOD')
2775-
Path to be modified. May always be specified as a str or bytes.
2775+
Path to be modified. May always be specified as a str, bytes, or a path-like object.
27762776
On some platforms, path may also be specified as an open file descriptor.
27772777
If this functionality is unavailable, using it raises an exception.
27782778
@@ -2803,7 +2803,7 @@ dir_fd and follow_symlinks may not be implemented on your platform.
28032803
static PyObject *
28042804
os_chmod_impl(PyObject *module, path_t *path, int mode, int dir_fd,
28052805
int follow_symlinks)
2806-
/*[clinic end generated code: output=5cf6a94915cc7bff input=7f1618e5e15cc196]*/
2806+
/*[clinic end generated code: output=5cf6a94915cc7bff input=989081551c00293b]*/
28072807
{
28082808
int result;
28092809

@@ -3123,7 +3123,7 @@ os_fdatasync_impl(PyObject *module, int fd)
31233123
os.chown
31243124
31253125
path : path_t(allow_fd='PATH_HAVE_FCHOWN')
3126-
Path to be examined; can be string, bytes, or open-file-descriptor int.
3126+
Path to be examined; can be string, bytes, a path-like object, or open-file-descriptor int.
31273127
31283128
uid: uid_t
31293129
@@ -3161,7 +3161,7 @@ dir_fd and follow_symlinks may not be implemented on your platform.
31613161
static PyObject *
31623162
os_chown_impl(PyObject *module, path_t *path, uid_t uid, gid_t gid,
31633163
int dir_fd, int follow_symlinks)
3164-
/*[clinic end generated code: output=4beadab0db5f70cd input=a61cc35574814d5d]*/
3164+
/*[clinic end generated code: output=4beadab0db5f70cd input=b08c5ec67996a97d]*/
31653165
{
31663166
int result;
31673167

@@ -3688,7 +3688,7 @@ os.listdir
36883688
36893689
Return a list containing the names of the files in the directory.
36903690
3691-
path can be specified as either str or bytes. If path is bytes,
3691+
path can be specified as either str, bytes, or a path-like object. If path is bytes,
36923692
the filenames returned will also be bytes; in all other circumstances
36933693
the filenames returned will be str.
36943694
If path is None, uses the path='.'.
@@ -3704,7 +3704,7 @@ entries '.' and '..' even if they are present in the directory.
37043704

37053705
static PyObject *
37063706
os_listdir_impl(PyObject *module, path_t *path)
3707-
/*[clinic end generated code: output=293045673fcd1a75 input=09e300416e3cd729]*/
3707+
/*[clinic end generated code: output=293045673fcd1a75 input=e3f58030f538295d]*/
37083708
{
37093709
#if defined(MS_WINDOWS) && !defined(HAVE_OPENDIR)
37103710
return _listdir_windows_no_opendir(path, NULL);
@@ -11415,7 +11415,7 @@ os.getxattr
1141511415
1141611416
Return the value of extended attribute attribute on path.
1141711417
11418-
path may be either a string or an open file descriptor.
11418+
path may be either a string, a path-like object, or an open file descriptor.
1141911419
If follow_symlinks is False, and the last element of the path is a symbolic
1142011420
link, getxattr will examine the symbolic link itself instead of the file
1142111421
the link points to.
@@ -11425,7 +11425,7 @@ If follow_symlinks is False, and the last element of the path is a symbolic
1142511425
static PyObject *
1142611426
os_getxattr_impl(PyObject *module, path_t *path, path_t *attribute,
1142711427
int follow_symlinks)
11428-
/*[clinic end generated code: output=5f2f44200a43cff2 input=8c8ea3bab78d89c2]*/
11428+
/*[clinic end generated code: output=5f2f44200a43cff2 input=025789491708f7eb]*/
1142911429
{
1143011430
Py_ssize_t i;
1143111431
PyObject *buffer = NULL;
@@ -11487,7 +11487,7 @@ os.setxattr
1148711487
1148811488
Set extended attribute attribute on path to value.
1148911489
11490-
path may be either a string or an open file descriptor.
11490+
path may be either a string, a path-like object, or an open file descriptor.
1149111491
If follow_symlinks is False, and the last element of the path is a symbolic
1149211492
link, setxattr will modify the symbolic link itself instead of the file
1149311493
the link points to.
@@ -11497,7 +11497,7 @@ If follow_symlinks is False, and the last element of the path is a symbolic
1149711497
static PyObject *
1149811498
os_setxattr_impl(PyObject *module, path_t *path, path_t *attribute,
1149911499
Py_buffer *value, int flags, int follow_symlinks)
11500-
/*[clinic end generated code: output=98b83f63fdde26bb input=f0d26833992015c2]*/
11500+
/*[clinic end generated code: output=98b83f63fdde26bb input=c17c0103009042f0]*/
1150111501
{
1150211502
ssize_t result;
1150311503

@@ -11535,7 +11535,7 @@ os.removexattr
1153511535
1153611536
Remove extended attribute attribute on path.
1153711537
11538-
path may be either a string or an open file descriptor.
11538+
path may be either a string, a path-like object, or an open file descriptor.
1153911539
If follow_symlinks is False, and the last element of the path is a symbolic
1154011540
link, removexattr will modify the symbolic link itself instead of the file
1154111541
the link points to.
@@ -11545,7 +11545,7 @@ If follow_symlinks is False, and the last element of the path is a symbolic
1154511545
static PyObject *
1154611546
os_removexattr_impl(PyObject *module, path_t *path, path_t *attribute,
1154711547
int follow_symlinks)
11548-
/*[clinic end generated code: output=521a51817980cda6 input=cdb54834161e3329]*/
11548+
/*[clinic end generated code: output=521a51817980cda6 input=3d9a7d36fe2f7c4e]*/
1154911549
{
1155011550
ssize_t result;
1155111551

@@ -11578,7 +11578,7 @@ os.listxattr
1157811578
1157911579
Return a list of extended attributes on path.
1158011580
11581-
path may be either None, a string, or an open file descriptor.
11581+
path may be either None, a string, a path-like object, or an open file descriptor.
1158211582
if path is None, listxattr will examine the current directory.
1158311583
If follow_symlinks is False, and the last element of the path is a symbolic
1158411584
link, listxattr will examine the symbolic link itself instead of the file
@@ -11587,7 +11587,7 @@ If follow_symlinks is False, and the last element of the path is a symbolic
1158711587

1158811588
static PyObject *
1158911589
os_listxattr_impl(PyObject *module, path_t *path, int follow_symlinks)
11590-
/*[clinic end generated code: output=bebdb4e2ad0ce435 input=08cca53ac0b07c13]*/
11590+
/*[clinic end generated code: output=bebdb4e2ad0ce435 input=9826edf9fdb90869]*/
1159111591
{
1159211592
Py_ssize_t i;
1159311593
PyObject *result = NULL;
@@ -12836,7 +12836,7 @@ os.scandir
1283612836
1283712837
Return an iterator of DirEntry objects for given path.
1283812838
12839-
path can be specified as either str, bytes or path-like object. If path
12839+
path can be specified as either str, bytes, or a path-like object. If path
1284012840
is bytes, the names of yielded DirEntry objects will also be bytes; in
1284112841
all other circumstances they will be str.
1284212842
@@ -12845,7 +12845,7 @@ If path is None, uses the path='.'.
1284512845

1284612846
static PyObject *
1284712847
os_scandir_impl(PyObject *module, path_t *path)
12848-
/*[clinic end generated code: output=6eb2668b675ca89e input=b139dc1c57f60846]*/
12848+
/*[clinic end generated code: output=6eb2668b675ca89e input=6bdd312708fc3bb0]*/
1284912849
{
1285012850
ScandirIterator *iterator;
1285112851
#ifdef MS_WINDOWS

0 commit comments

Comments
 (0)