@@ -35,9 +35,9 @@ Notes on the availability of these functions:
35
35
36
36
.. note ::
37
37
38
- All functions in this module raise :exc: `OSError ` in the case of invalid or
39
- inaccessible file names and paths, or other arguments that have the correct
40
- type, but are not accepted by the operating system.
38
+ All functions in this module raise :exc: `OSError ` (or subclasses thereof) in
39
+ the case of invalid or inaccessible file names and paths, or other arguments
40
+ that have the correct type, but are not accepted by the operating system.
41
41
42
42
.. exception :: error
43
43
@@ -1858,8 +1858,8 @@ features:
1858
1858
directories you can set the umask before invoking :func: `makedirs `. The
1859
1859
file permission bits of existing parent directories are not changed.
1860
1860
1861
- If *exist_ok * is ``False `` (the default), an :exc: `OSError ` is raised if the
1862
- target directory already exists.
1861
+ If *exist_ok * is ``False `` (the default), an :exc: `FileExistsError ` is
1862
+ raised if the target directory already exists.
1863
1863
1864
1864
.. note ::
1865
1865
@@ -2010,8 +2010,8 @@ features:
2010
2010
2011
2011
.. function :: remove(path, *, dir_fd=None)
2012
2012
2013
- Remove (delete) the file *path *. If *path * is a directory, :exc: ` OSError ` is
2014
- raised. Use :func: `rmdir ` to remove directories.
2013
+ Remove (delete) the file *path *. If *path * is a directory, an
2014
+ :exc: ` IsADirectoryError ` is raised. Use :func: `rmdir ` to remove directories.
2015
2015
2016
2016
This function can support :ref: `paths relative to directory descriptors
2017
2017
<dir_fd>`.
@@ -2048,13 +2048,19 @@ features:
2048
2048
2049
2049
.. function :: rename(src, dst, *, src_dir_fd=None, dst_dir_fd=None)
2050
2050
2051
- Rename the file or directory *src * to *dst *. If *dst * is a directory,
2052
- :exc: `OSError ` will be raised. On Unix, if *dst * exists and is a file, it will
2053
- be replaced silently if the user has permission. The operation may fail on some
2054
- Unix flavors if *src * and *dst * are on different filesystems. If successful,
2055
- the renaming will be an atomic operation (this is a POSIX requirement). On
2056
- Windows, if *dst * already exists, :exc: `OSError ` will be raised even if it is a
2057
- file.
2051
+ Rename the file or directory *src * to *dst *. If *dst * exists, the operation
2052
+ will fail with an :exc: `OSError ` subclass in a number of cases:
2053
+
2054
+ On Windows, if *dst * exists a :exc: `FileExistsError ` is always raised.
2055
+
2056
+ On Unix, if *src * is a file and *dst * is a directory or vice-versa, anq:q
2057
+ :exc: `IsADirectoryError ` or a :exc: `NotADirectoryError ` will be raised
2058
+ respectively. If both are directories and *dst * is empty, *dst * will be
2059
+ silently replaced. If *dst * is a non-empty directory, an :exc: `OSError `
2060
+ is raised. If both are files, *dst * it will be replaced silently if the user
2061
+ has permission. The operation may fail on some Unix flavors if *src * and
2062
+ *dst * are on different filesystems. If successful, the renaming will be an
2063
+ atomic operation (this is a POSIX requirement).
2058
2064
2059
2065
This function can support specifying *src_dir_fd * and/or *dst_dir_fd * to
2060
2066
supply :ref: `paths relative to directory descriptors <dir_fd >`.
@@ -2103,9 +2109,10 @@ features:
2103
2109
2104
2110
.. function :: rmdir(path, *, dir_fd=None)
2105
2111
2106
- Remove (delete) the directory *path *. Only works when the directory is
2107
- empty, otherwise, :exc: `OSError ` is raised. In order to remove whole
2108
- directory trees, :func: `shutil.rmtree ` can be used.
2112
+ Remove (delete) the directory *path *. If the directory does not exist or is
2113
+ not empty, an :exc: `FileNotFoundError ` or an :exc: `OSError ` is raised
2114
+ respectively. In order to remove whole directory trees,
2115
+ :func: `shutil.rmtree ` can be used.
2109
2116
2110
2117
This function can support :ref: `paths relative to directory descriptors
2111
2118
<dir_fd>`.
0 commit comments