From c018573440bb626813480ec5ddf40cd01b1a9951 Mon Sep 17 00:00:00 2001 From: Peter Bierma Date: Sun, 18 Aug 2024 08:23:34 -0400 Subject: [PATCH 01/13] Deprecate shutil.ExecError --- Lib/shutil.py | 16 +++++++++++++--- Lib/test/test_shutil.py | 4 +++- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/Lib/shutil.py b/Lib/shutil.py index 72b2d834dc387e..e06ff40c95c14a 100644 --- a/Lib/shutil.py +++ b/Lib/shutil.py @@ -56,7 +56,7 @@ __all__ = ["copyfileobj", "copyfile", "copymode", "copystat", "copy", "copy2", "copytree", "move", "rmtree", "Error", "SpecialFileError", - "ExecError", "make_archive", "get_archive_formats", + "make_archive", "get_archive_formats", "register_archive_format", "unregister_archive_format", "get_unpack_formats", "register_unpack_format", "unregister_unpack_format", "unpack_archive", @@ -74,8 +74,7 @@ class SpecialFileError(OSError): """Raised when trying to do a kind of operation (e.g. copying) which is not supported on a special file (e.g. a named pipe)""" -class ExecError(OSError): - """Raised when a command could not be executed""" +_ExecError = RuntimeError class ReadError(OSError): """Raised when an archive cannot be read""" @@ -1582,3 +1581,14 @@ def which(cmd, mode=os.F_OK | os.X_OK, path=None): if _access_check(name, mode): return name return None + +def __getattr__(name): + if name == "ExecError": + import warnings + warnings._deprecated( + "shutil.ExecError", + f"{warnings._DEPRECATED_MSG}; use RuntimeError instead", + remove=(3, 16) + ) + return _ExecError + raise AttributeError(f"module {__name__!r} has no attribute {name!r}") diff --git a/Lib/test/test_shutil.py b/Lib/test/test_shutil.py index c770be21b41c2b..80e1d73b6b2aab 100644 --- a/Lib/test/test_shutil.py +++ b/Lib/test/test_shutil.py @@ -3393,7 +3393,7 @@ def test_module_all_attribute(self): self.assertTrue(hasattr(shutil, '__all__')) target_api = ['copyfileobj', 'copyfile', 'copymode', 'copystat', 'copy', 'copy2', 'copytree', 'move', 'rmtree', 'Error', - 'SpecialFileError', 'ExecError', 'make_archive', + 'SpecialFileError', 'make_archive', 'get_archive_formats', 'register_archive_format', 'unregister_archive_format', 'get_unpack_formats', 'register_unpack_format', 'unregister_unpack_format', @@ -3402,6 +3402,8 @@ def test_module_all_attribute(self): if hasattr(os, 'statvfs') or os.name == 'nt': target_api.append('disk_usage') self.assertEqual(set(shutil.__all__), set(target_api)) + with self.assertWarns(DeprecationWarning): + from shutil import ExecError if __name__ == '__main__': From 8d6c22f71cfa6dd77437bfda6c0e5f34bc9a2d91 Mon Sep 17 00:00:00 2001 From: Peter Bierma Date: Sun, 18 Aug 2024 08:25:38 -0400 Subject: [PATCH 02/13] Add NEWS entry. --- .../next/Library/2024-08-18-08-25-32.gh-issue-123084.rf8izX.rst | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2024-08-18-08-25-32.gh-issue-123084.rf8izX.rst diff --git a/Misc/NEWS.d/next/Library/2024-08-18-08-25-32.gh-issue-123084.rf8izX.rst b/Misc/NEWS.d/next/Library/2024-08-18-08-25-32.gh-issue-123084.rf8izX.rst new file mode 100644 index 00000000000000..e6ea91bdbb4fdf --- /dev/null +++ b/Misc/NEWS.d/next/Library/2024-08-18-08-25-32.gh-issue-123084.rf8izX.rst @@ -0,0 +1,2 @@ +:class:`!shutil.ExecError` is now a deprecated alias of +:class:`RuntimeError`. From 35b2c44dbdf1308e0773a62478e793fae9c24a7e Mon Sep 17 00:00:00 2001 From: Peter Bierma Date: Sun, 18 Aug 2024 08:37:43 -0400 Subject: [PATCH 03/13] Add pending removal entry. --- Doc/deprecations/pending-removal-in-future.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Doc/deprecations/pending-removal-in-future.rst b/Doc/deprecations/pending-removal-in-future.rst index 6942b9d62cb8f2..2d14546458ab40 100644 --- a/Doc/deprecations/pending-removal-in-future.rst +++ b/Doc/deprecations/pending-removal-in-future.rst @@ -154,3 +154,6 @@ although there is currently no date scheduled for their removal. * :meth:`zipimport.zipimporter.load_module` is deprecated: use :meth:`~zipimport.zipimporter.exec_module` instead. + +* :class:`!shutil.ExecError` is deprecated: + use :class:`RuntimeError` instead. From 13c6e528fe572691fe58d1a797757c27c26a8939 Mon Sep 17 00:00:00 2001 From: Peter Bierma Date: Tue, 20 Aug 2024 18:22:04 -0400 Subject: [PATCH 04/13] Update shutil.py Co-authored-by: Barney Gale --- Lib/shutil.py | 1 - 1 file changed, 1 deletion(-) diff --git a/Lib/shutil.py b/Lib/shutil.py index e06ff40c95c14a..d39db9ec0ecf19 100644 --- a/Lib/shutil.py +++ b/Lib/shutil.py @@ -74,7 +74,6 @@ class SpecialFileError(OSError): """Raised when trying to do a kind of operation (e.g. copying) which is not supported on a special file (e.g. a named pipe)""" -_ExecError = RuntimeError class ReadError(OSError): """Raised when an archive cannot be read""" From 3eb7294486c33dc998ca8bc49a9e079363f04c41 Mon Sep 17 00:00:00 2001 From: Peter Bierma Date: Tue, 20 Aug 2024 18:22:10 -0400 Subject: [PATCH 05/13] Update shutil.py Co-authored-by: Barney Gale --- Lib/shutil.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/shutil.py b/Lib/shutil.py index d39db9ec0ecf19..b5e8706c2cdfb9 100644 --- a/Lib/shutil.py +++ b/Lib/shutil.py @@ -1589,5 +1589,5 @@ def __getattr__(name): f"{warnings._DEPRECATED_MSG}; use RuntimeError instead", remove=(3, 16) ) - return _ExecError + return RuntimeError raise AttributeError(f"module {__name__!r} has no attribute {name!r}") From ecfd65fc2f74a0baf1073e1591e80c3bd2447ca2 Mon Sep 17 00:00:00 2001 From: Peter Bierma Date: Tue, 20 Aug 2024 18:30:03 -0400 Subject: [PATCH 06/13] Update pending-removal-in-future.rst --- Doc/deprecations/pending-removal-in-future.rst | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Doc/deprecations/pending-removal-in-future.rst b/Doc/deprecations/pending-removal-in-future.rst index 2d14546458ab40..40c6cef4692235 100644 --- a/Doc/deprecations/pending-removal-in-future.rst +++ b/Doc/deprecations/pending-removal-in-future.rst @@ -153,7 +153,4 @@ although there is currently no date scheduled for their removal. ``elem is not None`` tests instead. * :meth:`zipimport.zipimporter.load_module` is deprecated: - use :meth:`~zipimport.zipimporter.exec_module` instead. - -* :class:`!shutil.ExecError` is deprecated: - use :class:`RuntimeError` instead. + use :meth:`~zipimport.zipimporter.exec_module` instead. \ No newline at end of file From c499cd60a95289f78a09462d6b82105398c497e6 Mon Sep 17 00:00:00 2001 From: Peter Bierma Date: Tue, 20 Aug 2024 18:30:28 -0400 Subject: [PATCH 07/13] Update pending-removal-in-3.16.rst --- Doc/deprecations/pending-removal-in-3.16.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Doc/deprecations/pending-removal-in-3.16.rst b/Doc/deprecations/pending-removal-in-3.16.rst index 10cb5e424a623b..daa24b02a131a1 100644 --- a/Doc/deprecations/pending-removal-in-3.16.rst +++ b/Doc/deprecations/pending-removal-in-3.16.rst @@ -8,3 +8,6 @@ Pending Removal in Python 3.16 * :mod:`symtable`: Deprecate :meth:`symtable.Class.get_methods` due to the lack of interest. (Contributed by Bénédikt Tran in :gh:`119698`.) + +* :class:`!shutil.ExecError` is deprecated: + use :class:`RuntimeError` instead. \ No newline at end of file From 20eb07b08cfa9eb8113990816ef4ab49cfceddf0 Mon Sep 17 00:00:00 2001 From: Peter Bierma Date: Tue, 20 Aug 2024 18:45:54 -0400 Subject: [PATCH 08/13] Update 2024-08-18-08-25-32.gh-issue-123084.rf8izX.rst Co-authored-by: Barney Gale --- .../Library/2024-08-18-08-25-32.gh-issue-123084.rf8izX.rst | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Misc/NEWS.d/next/Library/2024-08-18-08-25-32.gh-issue-123084.rf8izX.rst b/Misc/NEWS.d/next/Library/2024-08-18-08-25-32.gh-issue-123084.rf8izX.rst index e6ea91bdbb4fdf..2143604c899cfa 100644 --- a/Misc/NEWS.d/next/Library/2024-08-18-08-25-32.gh-issue-123084.rf8izX.rst +++ b/Misc/NEWS.d/next/Library/2024-08-18-08-25-32.gh-issue-123084.rf8izX.rst @@ -1,2 +1,3 @@ -:class:`!shutil.ExecError` is now a deprecated alias of -:class:`RuntimeError`. +Deprecate :class:`!shutil.ExecError`, which hasn't been +raised by any :mod:`shutil` function since Python 3.4. It's +now an alias for :exc:`RuntimeError`. From 94f313d0a82075a39bd9f10c305be4f32f2638e3 Mon Sep 17 00:00:00 2001 From: Peter Bierma Date: Tue, 20 Aug 2024 18:46:00 -0400 Subject: [PATCH 09/13] Update shutil.py Co-authored-by: Barney Gale --- Lib/shutil.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Lib/shutil.py b/Lib/shutil.py index b5e8706c2cdfb9..6037092a5e09f2 100644 --- a/Lib/shutil.py +++ b/Lib/shutil.py @@ -1586,7 +1586,8 @@ def __getattr__(name): import warnings warnings._deprecated( "shutil.ExecError", - f"{warnings._DEPRECATED_MSG}; use RuntimeError instead", + f"{warnings._DEPRECATED_MSG}; it " + "isn't raised by any shutil function.", remove=(3, 16) ) return RuntimeError From 38904108f96d20a60332a79bc2457c20419825a7 Mon Sep 17 00:00:00 2001 From: Peter Bierma Date: Tue, 20 Aug 2024 18:46:06 -0400 Subject: [PATCH 10/13] Update pending-removal-in-3.16.rst Co-authored-by: Barney Gale --- Doc/deprecations/pending-removal-in-3.16.rst | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Doc/deprecations/pending-removal-in-3.16.rst b/Doc/deprecations/pending-removal-in-3.16.rst index daa24b02a131a1..8252f30fcefbc5 100644 --- a/Doc/deprecations/pending-removal-in-3.16.rst +++ b/Doc/deprecations/pending-removal-in-3.16.rst @@ -9,5 +9,6 @@ Pending Removal in Python 3.16 Deprecate :meth:`symtable.Class.get_methods` due to the lack of interest. (Contributed by Bénédikt Tran in :gh:`119698`.) -* :class:`!shutil.ExecError` is deprecated: - use :class:`RuntimeError` instead. \ No newline at end of file +* :mod:`shutil`: Deprecate :class:`!shutil.ExecError`, which hasn't + been raised by any :mod:`!shutil` function since Python 3.4. It's + now an alias for :exc:`RuntimeError`. \ No newline at end of file From 3542d4ec65c3cda980c8c5bd6df40d9098fb78d5 Mon Sep 17 00:00:00 2001 From: Peter Bierma Date: Tue, 20 Aug 2024 19:02:17 -0400 Subject: [PATCH 11/13] Update pending-removal-in-future.rst --- Doc/deprecations/pending-removal-in-future.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/deprecations/pending-removal-in-future.rst b/Doc/deprecations/pending-removal-in-future.rst index 40c6cef4692235..6942b9d62cb8f2 100644 --- a/Doc/deprecations/pending-removal-in-future.rst +++ b/Doc/deprecations/pending-removal-in-future.rst @@ -153,4 +153,4 @@ although there is currently no date scheduled for their removal. ``elem is not None`` tests instead. * :meth:`zipimport.zipimporter.load_module` is deprecated: - use :meth:`~zipimport.zipimporter.exec_module` instead. \ No newline at end of file + use :meth:`~zipimport.zipimporter.exec_module` instead. From 56c8b28b8e63539af9b74b256e6aa487811bd22b Mon Sep 17 00:00:00 2001 From: Peter Bierma Date: Tue, 20 Aug 2024 19:31:32 -0400 Subject: [PATCH 12/13] Update 2024-08-18-08-25-32.gh-issue-123084.rf8izX.rst --- .../next/Library/2024-08-18-08-25-32.gh-issue-123084.rf8izX.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Library/2024-08-18-08-25-32.gh-issue-123084.rf8izX.rst b/Misc/NEWS.d/next/Library/2024-08-18-08-25-32.gh-issue-123084.rf8izX.rst index 2143604c899cfa..aedb9a09e7ae86 100644 --- a/Misc/NEWS.d/next/Library/2024-08-18-08-25-32.gh-issue-123084.rf8izX.rst +++ b/Misc/NEWS.d/next/Library/2024-08-18-08-25-32.gh-issue-123084.rf8izX.rst @@ -1,3 +1,3 @@ Deprecate :class:`!shutil.ExecError`, which hasn't been raised by any :mod:`shutil` function since Python 3.4. It's -now an alias for :exc:`RuntimeError`. +now an alias for :exc:`RuntimeError`. \ No newline at end of file From 17bb148069bdd956b820432f4affa05a42bcb0ec Mon Sep 17 00:00:00 2001 From: Peter Bierma Date: Tue, 20 Aug 2024 20:13:08 -0400 Subject: [PATCH 13/13] Fix failing lint. --- Doc/deprecations/pending-removal-in-3.16.rst | 3 ++- .../Library/2024-08-18-08-25-32.gh-issue-123084.rf8izX.rst | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Doc/deprecations/pending-removal-in-3.16.rst b/Doc/deprecations/pending-removal-in-3.16.rst index 8252f30fcefbc5..de134f8e2ee9d3 100644 --- a/Doc/deprecations/pending-removal-in-3.16.rst +++ b/Doc/deprecations/pending-removal-in-3.16.rst @@ -11,4 +11,5 @@ Pending Removal in Python 3.16 * :mod:`shutil`: Deprecate :class:`!shutil.ExecError`, which hasn't been raised by any :mod:`!shutil` function since Python 3.4. It's - now an alias for :exc:`RuntimeError`. \ No newline at end of file + now an alias for :exc:`RuntimeError`. + diff --git a/Misc/NEWS.d/next/Library/2024-08-18-08-25-32.gh-issue-123084.rf8izX.rst b/Misc/NEWS.d/next/Library/2024-08-18-08-25-32.gh-issue-123084.rf8izX.rst index aedb9a09e7ae86..eb01d66d98aef6 100644 --- a/Misc/NEWS.d/next/Library/2024-08-18-08-25-32.gh-issue-123084.rf8izX.rst +++ b/Misc/NEWS.d/next/Library/2024-08-18-08-25-32.gh-issue-123084.rf8izX.rst @@ -1,3 +1,4 @@ Deprecate :class:`!shutil.ExecError`, which hasn't been raised by any :mod:`shutil` function since Python 3.4. It's -now an alias for :exc:`RuntimeError`. \ No newline at end of file +now an alias for :exc:`RuntimeError`. +