From 28e1c912b1e565f6d256818715f0709d845ec883 Mon Sep 17 00:00:00 2001 From: mohsinm-dev Date: Thu, 26 Feb 2026 21:17:05 +0500 Subject: [PATCH 1/3] gh-145227: Clarify os.remove() directory exception is platform-dependent --- Doc/library/os.rst | 4 +++- .../2026-02-26-21-09-18.gh-issue-145227.yVAgmv.rst | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 Misc/NEWS.d/next/Documentation/2026-02-26-21-09-18.gh-issue-145227.yVAgmv.rst diff --git a/Doc/library/os.rst b/Doc/library/os.rst index 7418f3a8bacb0f..f6278dc7a09337 100644 --- a/Doc/library/os.rst +++ b/Doc/library/os.rst @@ -2732,7 +2732,9 @@ features: .. function:: remove(path, *, dir_fd=None) Remove (delete) the file *path*. If *path* is a directory, an - :exc:`OSError` is raised. Use :func:`rmdir` to remove directories. + :exc:`OSError` is raised. The exact exception type depends on the platform: + for example, :exc:`IsADirectoryError` or :exc:`PermissionError`. + Use :func:`rmdir` to remove directories. If the file does not exist, a :exc:`FileNotFoundError` is raised. This function can support :ref:`paths relative to directory descriptors diff --git a/Misc/NEWS.d/next/Documentation/2026-02-26-21-09-18.gh-issue-145227.yVAgmv.rst b/Misc/NEWS.d/next/Documentation/2026-02-26-21-09-18.gh-issue-145227.yVAgmv.rst new file mode 100644 index 00000000000000..6fb1525f62aa21 --- /dev/null +++ b/Misc/NEWS.d/next/Documentation/2026-02-26-21-09-18.gh-issue-145227.yVAgmv.rst @@ -0,0 +1,2 @@ +Clarify that the :exc:`OSError` subclass raised by :func:`os.remove` when the +path is a directory is platform-dependent. From d0678710c3d5911241abb51e22576fb3c2672df4 Mon Sep 17 00:00:00 2001 From: mohsinm-dev Date: Fri, 27 Feb 2026 01:01:21 +0500 Subject: [PATCH 2/3] Remove unnecessary NEWS entry for docs-only change --- .../2026-02-26-21-09-18.gh-issue-145227.yVAgmv.rst | 2 -- 1 file changed, 2 deletions(-) delete mode 100644 Misc/NEWS.d/next/Documentation/2026-02-26-21-09-18.gh-issue-145227.yVAgmv.rst diff --git a/Misc/NEWS.d/next/Documentation/2026-02-26-21-09-18.gh-issue-145227.yVAgmv.rst b/Misc/NEWS.d/next/Documentation/2026-02-26-21-09-18.gh-issue-145227.yVAgmv.rst deleted file mode 100644 index 6fb1525f62aa21..00000000000000 --- a/Misc/NEWS.d/next/Documentation/2026-02-26-21-09-18.gh-issue-145227.yVAgmv.rst +++ /dev/null @@ -1,2 +0,0 @@ -Clarify that the :exc:`OSError` subclass raised by :func:`os.remove` when the -path is a directory is platform-dependent. From 576783d03642ec7a4dad3b692055426cd6ee953e Mon Sep 17 00:00:00 2001 From: mohsinm-dev Date: Fri, 27 Feb 2026 04:14:33 +0500 Subject: [PATCH 3/3] Add platform examples per review feedback --- Doc/library/os.rst | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Doc/library/os.rst b/Doc/library/os.rst index f6278dc7a09337..947c58afcd74aa 100644 --- a/Doc/library/os.rst +++ b/Doc/library/os.rst @@ -2732,8 +2732,9 @@ features: .. function:: remove(path, *, dir_fd=None) Remove (delete) the file *path*. If *path* is a directory, an - :exc:`OSError` is raised. The exact exception type depends on the platform: - for example, :exc:`IsADirectoryError` or :exc:`PermissionError`. + :exc:`OSError` is raised. The exact subclass depends on the platform: + for example, :exc:`IsADirectoryError` on Linux or :exc:`PermissionError` + on macOS. Use :func:`rmdir` to remove directories. If the file does not exist, a :exc:`FileNotFoundError` is raised.