mirror of
https://github.com/python/cpython.git
synced 2025-09-28 19:25:27 +00:00
Use OSError subclasses in os documentation (GH-14262)
This commit is contained in:
parent
2f19e82fbe
commit
a55f75a6e3
1 changed files with 24 additions and 17 deletions
|
@ -36,9 +36,9 @@ Notes on the availability of these functions:
|
||||||
|
|
||||||
.. note::
|
.. note::
|
||||||
|
|
||||||
All functions in this module raise :exc:`OSError` in the case of invalid or
|
All functions in this module raise :exc:`OSError` (or subclasses thereof) in
|
||||||
inaccessible file names and paths, or other arguments that have the correct
|
the case of invalid or inaccessible file names and paths, or other arguments
|
||||||
type, but are not accepted by the operating system.
|
that have the correct type, but are not accepted by the operating system.
|
||||||
|
|
||||||
.. exception:: error
|
.. exception:: error
|
||||||
|
|
||||||
|
@ -1898,8 +1898,8 @@ features:
|
||||||
directories you can set the umask before invoking :func:`makedirs`. The
|
directories you can set the umask before invoking :func:`makedirs`. The
|
||||||
file permission bits of existing parent directories are not changed.
|
file permission bits of existing parent directories are not changed.
|
||||||
|
|
||||||
If *exist_ok* is ``False`` (the default), an :exc:`OSError` is raised if the
|
If *exist_ok* is ``False`` (the default), an :exc:`FileExistsError` is
|
||||||
target directory already exists.
|
raised if the target directory already exists.
|
||||||
|
|
||||||
.. note::
|
.. note::
|
||||||
|
|
||||||
|
@ -2052,8 +2052,8 @@ features:
|
||||||
|
|
||||||
.. function:: remove(path, *, dir_fd=None)
|
.. function:: remove(path, *, dir_fd=None)
|
||||||
|
|
||||||
Remove (delete) the file *path*. If *path* is a directory, :exc:`OSError` is
|
Remove (delete) the file *path*. If *path* is a directory, an
|
||||||
raised. Use :func:`rmdir` to remove directories.
|
:exc:`IsADirectoryError` is raised. Use :func:`rmdir` to remove directories.
|
||||||
|
|
||||||
This function can support :ref:`paths relative to directory descriptors
|
This function can support :ref:`paths relative to directory descriptors
|
||||||
<dir_fd>`.
|
<dir_fd>`.
|
||||||
|
@ -2090,13 +2090,19 @@ features:
|
||||||
|
|
||||||
.. function:: rename(src, dst, *, src_dir_fd=None, dst_dir_fd=None)
|
.. function:: rename(src, dst, *, src_dir_fd=None, dst_dir_fd=None)
|
||||||
|
|
||||||
Rename the file or directory *src* to *dst*. If *dst* is a directory,
|
Rename the file or directory *src* to *dst*. If *dst* exists, the operation
|
||||||
:exc:`OSError` will be raised. On Unix, if *dst* exists and is a file, it will
|
will fail with an :exc:`OSError` subclass in a number of cases:
|
||||||
be replaced silently if the user has permission. The operation may fail on some
|
|
||||||
Unix flavors if *src* and *dst* are on different filesystems. If successful,
|
On Windows, if *dst* exists a :exc:`FileExistsError` is always raised.
|
||||||
the renaming will be an atomic operation (this is a POSIX requirement). On
|
|
||||||
Windows, if *dst* already exists, :exc:`OSError` will be raised even if it is a
|
On Unix, if *src* is a file and *dst* is a directory or vice-versa, anq:q
|
||||||
file.
|
:exc:`IsADirectoryError` or a :exc:`NotADirectoryError` will be raised
|
||||||
|
respectively. If both are directories and *dst* is empty, *dst* will be
|
||||||
|
silently replaced. If *dst* is a non-empty directory, an :exc:`OSError`
|
||||||
|
is raised. If both are files, *dst* it will be replaced silently if the user
|
||||||
|
has permission. The operation may fail on some Unix flavors if *src* and
|
||||||
|
*dst* are on different filesystems. If successful, the renaming will be an
|
||||||
|
atomic operation (this is a POSIX requirement).
|
||||||
|
|
||||||
This function can support specifying *src_dir_fd* and/or *dst_dir_fd* to
|
This function can support specifying *src_dir_fd* and/or *dst_dir_fd* to
|
||||||
supply :ref:`paths relative to directory descriptors <dir_fd>`.
|
supply :ref:`paths relative to directory descriptors <dir_fd>`.
|
||||||
|
@ -2145,9 +2151,10 @@ features:
|
||||||
|
|
||||||
.. function:: rmdir(path, *, dir_fd=None)
|
.. function:: rmdir(path, *, dir_fd=None)
|
||||||
|
|
||||||
Remove (delete) the directory *path*. Only works when the directory is
|
Remove (delete) the directory *path*. If the directory does not exist or is
|
||||||
empty, otherwise, :exc:`OSError` is raised. In order to remove whole
|
not empty, an :exc:`FileNotFoundError` or an :exc:`OSError` is raised
|
||||||
directory trees, :func:`shutil.rmtree` can be used.
|
respectively. In order to remove whole directory trees,
|
||||||
|
:func:`shutil.rmtree` can be used.
|
||||||
|
|
||||||
This function can support :ref:`paths relative to directory descriptors
|
This function can support :ref:`paths relative to directory descriptors
|
||||||
<dir_fd>`.
|
<dir_fd>`.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue