Skip to content

Commit 08026b1

Browse files
BNMetricspablogsal
authored andcommitted
[3.7]bpo-29341: Backport b942707 3.7 (#10298)
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.. (cherry picked from commit b942707) Co-authored-by: BNMetrics <[email protected]>
1 parent 04c9666 commit 08026b1

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
@@ -2446,7 +2446,7 @@ class sched_param_converter(CConverter):
24462446
os.stat
24472447
24482448
path : path_t(allow_fd=True)
2449-
Path to be examined; can be string, bytes, path-like object or
2449+
Path to be examined; can be string, bytes, a path-like object or
24502450
open-file-descriptor int.
24512451
24522452
*
@@ -2474,7 +2474,7 @@ It's an error to use dir_fd or follow_symlinks when specifying path as
24742474

24752475
static PyObject *
24762476
os_stat_impl(PyObject *module, path_t *path, int dir_fd, int follow_symlinks)
2477-
/*[clinic end generated code: output=7d4976e6f18a59c5 input=270bd64e7bb3c8f7]*/
2477+
/*[clinic end generated code: output=7d4976e6f18a59c5 input=01d362ebcc06996b]*/
24782478
{
24792479
return posix_do_stat("stat", path, dir_fd, follow_symlinks);
24802480
}
@@ -2508,7 +2508,7 @@ os_lstat_impl(PyObject *module, path_t *path, int dir_fd)
25082508
os.access -> bool
25092509
25102510
path: path_t
2511-
Path to be tested; can be string or bytes
2511+
Path to be tested; can be string, bytes, or a path-like object.
25122512
25132513
mode: int
25142514
Operating-system mode bitfield. Can be F_OK to test existence,
@@ -2546,7 +2546,7 @@ Note that most operations will use the effective uid/gid, therefore this
25462546
static int
25472547
os_access_impl(PyObject *module, path_t *path, int mode, int dir_fd,
25482548
int effective_ids, int follow_symlinks)
2549-
/*[clinic end generated code: output=cf84158bc90b1a77 input=8e8c3a6ba791fee3]*/
2549+
/*[clinic end generated code: output=cf84158bc90b1a77 input=3ffe4e650ee3bf20]*/
25502550
{
25512551
int return_value;
25522552

@@ -2738,7 +2738,7 @@ os_fchdir_impl(PyObject *module, int fd)
27382738
os.chmod
27392739
27402740
path: path_t(allow_fd='PATH_HAVE_FCHMOD')
2741-
Path to be modified. May always be specified as a str or bytes.
2741+
Path to be modified. May always be specified as a str, bytes, or a path-like object.
27422742
On some platforms, path may also be specified as an open file descriptor.
27432743
If this functionality is unavailable, using it raises an exception.
27442744
@@ -2769,7 +2769,7 @@ dir_fd and follow_symlinks may not be implemented on your platform.
27692769
static PyObject *
27702770
os_chmod_impl(PyObject *module, path_t *path, int mode, int dir_fd,
27712771
int follow_symlinks)
2772-
/*[clinic end generated code: output=5cf6a94915cc7bff input=7f1618e5e15cc196]*/
2772+
/*[clinic end generated code: output=5cf6a94915cc7bff input=989081551c00293b]*/
27732773
{
27742774
int result;
27752775

@@ -3089,7 +3089,7 @@ os_fdatasync_impl(PyObject *module, int fd)
30893089
os.chown
30903090
30913091
path : path_t(allow_fd='PATH_HAVE_FCHOWN')
3092-
Path to be examined; can be string, bytes, or open-file-descriptor int.
3092+
Path to be examined; can be string, bytes, a path-like object, or open-file-descriptor int.
30933093
30943094
uid: uid_t
30953095
@@ -3127,7 +3127,7 @@ dir_fd and follow_symlinks may not be implemented on your platform.
31273127
static PyObject *
31283128
os_chown_impl(PyObject *module, path_t *path, uid_t uid, gid_t gid,
31293129
int dir_fd, int follow_symlinks)
3130-
/*[clinic end generated code: output=4beadab0db5f70cd input=a61cc35574814d5d]*/
3130+
/*[clinic end generated code: output=4beadab0db5f70cd input=b08c5ec67996a97d]*/
31313131
{
31323132
int result;
31333133

@@ -3654,7 +3654,7 @@ os.listdir
36543654
36553655
Return a list containing the names of the files in the directory.
36563656
3657-
path can be specified as either str or bytes. If path is bytes,
3657+
path can be specified as either str, bytes, or a path-like object. If path is bytes,
36583658
the filenames returned will also be bytes; in all other circumstances
36593659
the filenames returned will be str.
36603660
If path is None, uses the path='.'.
@@ -3670,7 +3670,7 @@ entries '.' and '..' even if they are present in the directory.
36703670

36713671
static PyObject *
36723672
os_listdir_impl(PyObject *module, path_t *path)
3673-
/*[clinic end generated code: output=293045673fcd1a75 input=09e300416e3cd729]*/
3673+
/*[clinic end generated code: output=293045673fcd1a75 input=e3f58030f538295d]*/
36743674
{
36753675
#if defined(MS_WINDOWS) && !defined(HAVE_OPENDIR)
36763676
return _listdir_windows_no_opendir(path, NULL);
@@ -10973,7 +10973,7 @@ os.getxattr
1097310973
1097410974
Return the value of extended attribute attribute on path.
1097510975
10976-
path may be either a string or an open file descriptor.
10976+
path may be either a string, a path-like object, or an open file descriptor.
1097710977
If follow_symlinks is False, and the last element of the path is a symbolic
1097810978
link, getxattr will examine the symbolic link itself instead of the file
1097910979
the link points to.
@@ -10983,7 +10983,7 @@ If follow_symlinks is False, and the last element of the path is a symbolic
1098310983
static PyObject *
1098410984
os_getxattr_impl(PyObject *module, path_t *path, path_t *attribute,
1098510985
int follow_symlinks)
10986-
/*[clinic end generated code: output=5f2f44200a43cff2 input=8c8ea3bab78d89c2]*/
10986+
/*[clinic end generated code: output=5f2f44200a43cff2 input=025789491708f7eb]*/
1098710987
{
1098810988
Py_ssize_t i;
1098910989
PyObject *buffer = NULL;
@@ -11045,7 +11045,7 @@ os.setxattr
1104511045
1104611046
Set extended attribute attribute on path to value.
1104711047
11048-
path may be either a string or an open file descriptor.
11048+
path may be either a string, a path-like object, or an open file descriptor.
1104911049
If follow_symlinks is False, and the last element of the path is a symbolic
1105011050
link, setxattr will modify the symbolic link itself instead of the file
1105111051
the link points to.
@@ -11055,7 +11055,7 @@ If follow_symlinks is False, and the last element of the path is a symbolic
1105511055
static PyObject *
1105611056
os_setxattr_impl(PyObject *module, path_t *path, path_t *attribute,
1105711057
Py_buffer *value, int flags, int follow_symlinks)
11058-
/*[clinic end generated code: output=98b83f63fdde26bb input=f0d26833992015c2]*/
11058+
/*[clinic end generated code: output=98b83f63fdde26bb input=c17c0103009042f0]*/
1105911059
{
1106011060
ssize_t result;
1106111061

@@ -11093,7 +11093,7 @@ os.removexattr
1109311093
1109411094
Remove extended attribute attribute on path.
1109511095
11096-
path may be either a string or an open file descriptor.
11096+
path may be either a string, a path-like object, or an open file descriptor.
1109711097
If follow_symlinks is False, and the last element of the path is a symbolic
1109811098
link, removexattr will modify the symbolic link itself instead of the file
1109911099
the link points to.
@@ -11103,7 +11103,7 @@ If follow_symlinks is False, and the last element of the path is a symbolic
1110311103
static PyObject *
1110411104
os_removexattr_impl(PyObject *module, path_t *path, path_t *attribute,
1110511105
int follow_symlinks)
11106-
/*[clinic end generated code: output=521a51817980cda6 input=cdb54834161e3329]*/
11106+
/*[clinic end generated code: output=521a51817980cda6 input=3d9a7d36fe2f7c4e]*/
1110711107
{
1110811108
ssize_t result;
1110911109

@@ -11136,7 +11136,7 @@ os.listxattr
1113611136
1113711137
Return a list of extended attributes on path.
1113811138
11139-
path may be either None, a string, or an open file descriptor.
11139+
path may be either None, a string, a path-like object, or an open file descriptor.
1114011140
if path is None, listxattr will examine the current directory.
1114111141
If follow_symlinks is False, and the last element of the path is a symbolic
1114211142
link, listxattr will examine the symbolic link itself instead of the file
@@ -11145,7 +11145,7 @@ If follow_symlinks is False, and the last element of the path is a symbolic
1114511145

1114611146
static PyObject *
1114711147
os_listxattr_impl(PyObject *module, path_t *path, int follow_symlinks)
11148-
/*[clinic end generated code: output=bebdb4e2ad0ce435 input=08cca53ac0b07c13]*/
11148+
/*[clinic end generated code: output=bebdb4e2ad0ce435 input=9826edf9fdb90869]*/
1114911149
{
1115011150
Py_ssize_t i;
1115111151
PyObject *result = NULL;
@@ -12392,7 +12392,7 @@ os.scandir
1239212392
1239312393
Return an iterator of DirEntry objects for given path.
1239412394
12395-
path can be specified as either str, bytes or path-like object. If path
12395+
path can be specified as either str, bytes, or a path-like object. If path
1239612396
is bytes, the names of yielded DirEntry objects will also be bytes; in
1239712397
all other circumstances they will be str.
1239812398
@@ -12401,7 +12401,7 @@ If path is None, uses the path='.'.
1240112401

1240212402
static PyObject *
1240312403
os_scandir_impl(PyObject *module, path_t *path)
12404-
/*[clinic end generated code: output=6eb2668b675ca89e input=b139dc1c57f60846]*/
12404+
/*[clinic end generated code: output=6eb2668b675ca89e input=6bdd312708fc3bb0]*/
1240512405
{
1240612406
ScandirIterator *iterator;
1240712407
#ifdef MS_WINDOWS

0 commit comments

Comments
 (0)