@@ -36,9 +36,9 @@ Notes on the availability of these functions:
3636
3737.. note ::
3838
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.
4242
4343.. exception :: error
4444
@@ -1898,8 +1898,8 @@ features:
18981898 directories you can set the umask before invoking :func: `makedirs `. The
18991899 file permission bits of existing parent directories are not changed.
19001900
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.
19031903
19041904 .. note ::
19051905
@@ -2052,8 +2052,8 @@ features:
20522052
20532053.. function :: remove(path, *, dir_fd=None)
20542054
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.
20572057
20582058 This function can support :ref: `paths relative to directory descriptors
20592059 <dir_fd>`.
@@ -2090,13 +2090,19 @@ features:
20902090
20912091.. function :: rename(src, dst, *, src_dir_fd=None, dst_dir_fd=None)
20922092
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).
21002106
21012107 This function can support specifying *src_dir_fd * and/or *dst_dir_fd * to
21022108 supply :ref: `paths relative to directory descriptors <dir_fd >`.
@@ -2145,9 +2151,10 @@ features:
21452151
21462152.. function :: rmdir(path, *, dir_fd=None)
21472153
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.
21512158
21522159 This function can support :ref: `paths relative to directory descriptors
21532160 <dir_fd>`.
0 commit comments