Skip to content

Commit 8d2f88f

Browse files
BNMetricspablogsal
authored andcommitted
[3.6]bpo-29341: Backport b942707 3.6 (GH-10299)
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 2339fe7 commit 8d2f88f

File tree

3 files changed

+30
-28
lines changed

3 files changed

+30
-28
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: 10 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Modules/posixmodule.c

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2391,7 +2391,7 @@ class sched_param_converter(CConverter):
23912391
os.stat
23922392
23932393
path : path_t(allow_fd=True)
2394-
Path to be examined; can be string, bytes, path-like object or
2394+
Path to be examined; can be string, bytes, a path-like object or
23952395
open-file-descriptor int.
23962396
23972397
*
@@ -2419,7 +2419,7 @@ It's an error to use dir_fd or follow_symlinks when specifying path as
24192419

24202420
static PyObject *
24212421
os_stat_impl(PyObject *module, path_t *path, int dir_fd, int follow_symlinks)
2422-
/*[clinic end generated code: output=7d4976e6f18a59c5 input=270bd64e7bb3c8f7]*/
2422+
/*[clinic end generated code: output=7d4976e6f18a59c5 input=01d362ebcc06996b]*/
24232423
{
24242424
return posix_do_stat("stat", path, dir_fd, follow_symlinks);
24252425
}
@@ -2453,7 +2453,7 @@ os_lstat_impl(PyObject *module, path_t *path, int dir_fd)
24532453
os.access -> bool
24542454
24552455
path: path_t
2456-
Path to be tested; can be string or bytes
2456+
Path to be tested; can be string, bytes, or a path-like object.
24572457
24582458
mode: int
24592459
Operating-system mode bitfield. Can be F_OK to test existence,
@@ -2491,7 +2491,7 @@ Note that most operations will use the effective uid/gid, therefore this
24912491
static int
24922492
os_access_impl(PyObject *module, path_t *path, int mode, int dir_fd,
24932493
int effective_ids, int follow_symlinks)
2494-
/*[clinic end generated code: output=cf84158bc90b1a77 input=8e8c3a6ba791fee3]*/
2494+
/*[clinic end generated code: output=cf84158bc90b1a77 input=3ffe4e650ee3bf20]*/
24952495
{
24962496
int return_value;
24972497

@@ -2683,7 +2683,7 @@ os_fchdir_impl(PyObject *module, int fd)
26832683
os.chmod
26842684
26852685
path: path_t(allow_fd='PATH_HAVE_FCHMOD')
2686-
Path to be modified. May always be specified as a str or bytes.
2686+
Path to be modified. May always be specified as a str, bytes, or a path-like object.
26872687
On some platforms, path may also be specified as an open file descriptor.
26882688
If this functionality is unavailable, using it raises an exception.
26892689
@@ -2714,7 +2714,7 @@ dir_fd and follow_symlinks may not be implemented on your platform.
27142714
static PyObject *
27152715
os_chmod_impl(PyObject *module, path_t *path, int mode, int dir_fd,
27162716
int follow_symlinks)
2717-
/*[clinic end generated code: output=5cf6a94915cc7bff input=7f1618e5e15cc196]*/
2717+
/*[clinic end generated code: output=5cf6a94915cc7bff input=989081551c00293b]*/
27182718
{
27192719
int result;
27202720

@@ -3034,7 +3034,7 @@ os_fdatasync_impl(PyObject *module, int fd)
30343034
os.chown
30353035
30363036
path : path_t(allow_fd='PATH_HAVE_FCHOWN')
3037-
Path to be examined; can be string, bytes, or open-file-descriptor int.
3037+
Path to be examined; can be string, bytes, a path-like object, or open-file-descriptor int.
30383038
30393039
uid: uid_t
30403040
@@ -3072,7 +3072,7 @@ dir_fd and follow_symlinks may not be implemented on your platform.
30723072
static PyObject *
30733073
os_chown_impl(PyObject *module, path_t *path, uid_t uid, gid_t gid,
30743074
int dir_fd, int follow_symlinks)
3075-
/*[clinic end generated code: output=4beadab0db5f70cd input=a61cc35574814d5d]*/
3075+
/*[clinic end generated code: output=4beadab0db5f70cd input=b08c5ec67996a97d]*/
30763076
{
30773077
int result;
30783078

@@ -3599,7 +3599,7 @@ os.listdir
35993599
36003600
Return a list containing the names of the files in the directory.
36013601
3602-
path can be specified as either str or bytes. If path is bytes,
3602+
path can be specified as either str, bytes, or a path-like object. If path is bytes,
36033603
the filenames returned will also be bytes; in all other circumstances
36043604
the filenames returned will be str.
36053605
If path is None, uses the path='.'.
@@ -3615,7 +3615,7 @@ entries '.' and '..' even if they are present in the directory.
36153615

36163616
static PyObject *
36173617
os_listdir_impl(PyObject *module, path_t *path)
3618-
/*[clinic end generated code: output=293045673fcd1a75 input=09e300416e3cd729]*/
3618+
/*[clinic end generated code: output=293045673fcd1a75 input=e3f58030f538295d]*/
36193619
{
36203620
#if defined(MS_WINDOWS) && !defined(HAVE_OPENDIR)
36213621
return _listdir_windows_no_opendir(path, NULL);
@@ -10667,7 +10667,7 @@ os.getxattr
1066710667
1066810668
Return the value of extended attribute attribute on path.
1066910669
10670-
path may be either a string or an open file descriptor.
10670+
path may be either a string, a path-like object, or an open file descriptor.
1067110671
If follow_symlinks is False, and the last element of the path is a symbolic
1067210672
link, getxattr will examine the symbolic link itself instead of the file
1067310673
the link points to.
@@ -10677,7 +10677,7 @@ If follow_symlinks is False, and the last element of the path is a symbolic
1067710677
static PyObject *
1067810678
os_getxattr_impl(PyObject *module, path_t *path, path_t *attribute,
1067910679
int follow_symlinks)
10680-
/*[clinic end generated code: output=5f2f44200a43cff2 input=8c8ea3bab78d89c2]*/
10680+
/*[clinic end generated code: output=5f2f44200a43cff2 input=025789491708f7eb]*/
1068110681
{
1068210682
Py_ssize_t i;
1068310683
PyObject *buffer = NULL;
@@ -10739,7 +10739,7 @@ os.setxattr
1073910739
1074010740
Set extended attribute attribute on path to value.
1074110741
10742-
path may be either a string or an open file descriptor.
10742+
path may be either a string, a path-like object, or an open file descriptor.
1074310743
If follow_symlinks is False, and the last element of the path is a symbolic
1074410744
link, setxattr will modify the symbolic link itself instead of the file
1074510745
the link points to.
@@ -10749,7 +10749,7 @@ If follow_symlinks is False, and the last element of the path is a symbolic
1074910749
static PyObject *
1075010750
os_setxattr_impl(PyObject *module, path_t *path, path_t *attribute,
1075110751
Py_buffer *value, int flags, int follow_symlinks)
10752-
/*[clinic end generated code: output=98b83f63fdde26bb input=f0d26833992015c2]*/
10752+
/*[clinic end generated code: output=98b83f63fdde26bb input=c17c0103009042f0]*/
1075310753
{
1075410754
ssize_t result;
1075510755

@@ -10787,7 +10787,7 @@ os.removexattr
1078710787
1078810788
Remove extended attribute attribute on path.
1078910789
10790-
path may be either a string or an open file descriptor.
10790+
path may be either a string, a path-like object, or an open file descriptor.
1079110791
If follow_symlinks is False, and the last element of the path is a symbolic
1079210792
link, removexattr will modify the symbolic link itself instead of the file
1079310793
the link points to.
@@ -10797,7 +10797,7 @@ If follow_symlinks is False, and the last element of the path is a symbolic
1079710797
static PyObject *
1079810798
os_removexattr_impl(PyObject *module, path_t *path, path_t *attribute,
1079910799
int follow_symlinks)
10800-
/*[clinic end generated code: output=521a51817980cda6 input=cdb54834161e3329]*/
10800+
/*[clinic end generated code: output=521a51817980cda6 input=3d9a7d36fe2f7c4e]*/
1080110801
{
1080210802
ssize_t result;
1080310803

@@ -10830,7 +10830,7 @@ os.listxattr
1083010830
1083110831
Return a list of extended attributes on path.
1083210832
10833-
path may be either None, a string, or an open file descriptor.
10833+
path may be either None, a string, a path-like object, or an open file descriptor.
1083410834
if path is None, listxattr will examine the current directory.
1083510835
If follow_symlinks is False, and the last element of the path is a symbolic
1083610836
link, listxattr will examine the symbolic link itself instead of the file
@@ -10839,7 +10839,7 @@ If follow_symlinks is False, and the last element of the path is a symbolic
1083910839

1084010840
static PyObject *
1084110841
os_listxattr_impl(PyObject *module, path_t *path, int follow_symlinks)
10842-
/*[clinic end generated code: output=bebdb4e2ad0ce435 input=08cca53ac0b07c13]*/
10842+
/*[clinic end generated code: output=bebdb4e2ad0ce435 input=9826edf9fdb90869]*/
1084310843
{
1084410844
Py_ssize_t i;
1084510845
PyObject *result = NULL;

0 commit comments

Comments
 (0)