@@ -36,9 +36,9 @@ Notes on the availability of these functions:
36
36
37
37
.. note ::
38
38
39
- All functions in this module raise :exc: `OSError ` in the case of invalid or
40
- inaccessible file names and paths, or other arguments that have the correct
41
- type, but are not accepted by the operating system.
39
+ All functions in this module raise :exc: `OSError ` (or subclasses thereof) in
40
+ the case of invalid or inaccessible file names and paths, or other arguments
41
+ that have the correct type, but are not accepted by the operating system.
42
42
43
43
.. exception :: error
44
44
@@ -1898,8 +1898,8 @@ features:
1898
1898
directories you can set the umask before invoking :func: `makedirs `. The
1899
1899
file permission bits of existing parent directories are not changed.
1900
1900
1901
- If *exist_ok * is ``False `` (the default), an :exc: `OSError ` is raised if the
1902
- target directory already exists.
1901
+ If *exist_ok * is ``False `` (the default), an :exc: `FileExistsError ` is
1902
+ raised if the target directory already exists.
1903
1903
1904
1904
.. note ::
1905
1905
@@ -2052,8 +2052,8 @@ features:
2052
2052
2053
2053
.. function :: remove(path, *, dir_fd=None)
2054
2054
2055
- Remove (delete) the file *path *. If *path * is a directory, :exc: ` OSError ` is
2056
- raised. Use :func: `rmdir ` to remove directories.
2055
+ Remove (delete) the file *path *. If *path * is a directory, an
2056
+ :exc: ` IsADirectoryError ` is raised. Use :func: `rmdir ` to remove directories.
2057
2057
2058
2058
This function can support :ref: `paths relative to directory descriptors
2059
2059
<dir_fd>`.
@@ -2090,13 +2090,19 @@ features:
2090
2090
2091
2091
.. function :: rename(src, dst, *, src_dir_fd=None, dst_dir_fd=None)
2092
2092
2093
- Rename the file or directory *src * to *dst *. If *dst * is a directory,
2094
- :exc: `OSError ` will be raised. On Unix, if *dst * exists and is a file, it will
2095
- be replaced silently if the user has permission. The operation may fail on some
2096
- Unix flavors if *src * and *dst * are on different filesystems. If successful,
2097
- the renaming will be an atomic operation (this is a POSIX requirement). On
2098
- Windows, if *dst * already exists, :exc: `OSError ` will be raised even if it is a
2099
- file.
2093
+ Rename the file or directory *src * to *dst *. If *dst * exists, the operation
2094
+ will fail with an :exc: `OSError ` subclass in a number of cases:
2095
+
2096
+ On Windows, if *dst * exists a :exc: `FileExistsError ` is always raised.
2097
+
2098
+ On Unix, if *src * is a file and *dst * is a directory or vice-versa, anq:q
2099
+ :exc: `IsADirectoryError ` or a :exc: `NotADirectoryError ` will be raised
2100
+ respectively. If both are directories and *dst * is empty, *dst * will be
2101
+ silently replaced. If *dst * is a non-empty directory, an :exc: `OSError `
2102
+ is raised. If both are files, *dst * it will be replaced silently if the user
2103
+ has permission. The operation may fail on some Unix flavors if *src * and
2104
+ *dst * are on different filesystems. If successful, the renaming will be an
2105
+ atomic operation (this is a POSIX requirement).
2100
2106
2101
2107
This function can support specifying *src_dir_fd * and/or *dst_dir_fd * to
2102
2108
supply :ref: `paths relative to directory descriptors <dir_fd >`.
@@ -2145,9 +2151,10 @@ features:
2145
2151
2146
2152
.. function :: rmdir(path, *, dir_fd=None)
2147
2153
2148
- Remove (delete) the directory *path *. Only works when the directory is
2149
- empty, otherwise, :exc: `OSError ` is raised. In order to remove whole
2150
- directory trees, :func: `shutil.rmtree ` can be used.
2154
+ Remove (delete) the directory *path *. If the directory does not exist or is
2155
+ not empty, an :exc: `FileNotFoundError ` or an :exc: `OSError ` is raised
2156
+ respectively. In order to remove whole directory trees,
2157
+ :func: `shutil.rmtree ` can be used.
2151
2158
2152
2159
This function can support :ref: `paths relative to directory descriptors
2153
2160
<dir_fd>`.
0 commit comments