mirror of
https://github.com/python/cpython.git
synced 2025-08-17 15:21:26 +00:00
[3.12] gh-112645: remove deprecation warning for use of onerror in shutil.rmtree (#112659) (#112665)
gh-112645: remove deprecation warning for use of onerror in shutil.rmtree (#112659)
(cherry picked from commit 97857ac058
)
This commit is contained in:
parent
b3b2706cad
commit
f5965c2385
4 changed files with 9 additions and 18 deletions
|
@ -838,8 +838,7 @@ shutil
|
||||||
|
|
||||||
* :func:`shutil.rmtree` now accepts a new argument *onexc* which is an
|
* :func:`shutil.rmtree` now accepts a new argument *onexc* which is an
|
||||||
error handler like *onerror* but which expects an exception instance
|
error handler like *onerror* but which expects an exception instance
|
||||||
rather than a *(typ, val, tb)* triplet. *onerror* is deprecated and
|
rather than a *(typ, val, tb)* triplet. *onerror* is deprecated.
|
||||||
will be removed in Python 3.14.
|
|
||||||
(Contributed by Irit Katriel in :gh:`102828`.)
|
(Contributed by Irit Katriel in :gh:`102828`.)
|
||||||
|
|
||||||
* :func:`shutil.which` now consults the *PATHEXT* environment variable to
|
* :func:`shutil.which` now consults the *PATHEXT* environment variable to
|
||||||
|
@ -1261,8 +1260,8 @@ Deprecated
|
||||||
:mod:`concurrent.futures` the fix is to use a different
|
:mod:`concurrent.futures` the fix is to use a different
|
||||||
:mod:`multiprocessing` start method such as ``"spawn"`` or ``"forkserver"``.
|
:mod:`multiprocessing` start method such as ``"spawn"`` or ``"forkserver"``.
|
||||||
|
|
||||||
* :mod:`shutil`: The *onerror* argument of :func:`shutil.rmtree` is deprecated and will be removed
|
* :mod:`shutil`: The *onerror* argument of :func:`shutil.rmtree` is deprecated;
|
||||||
in Python 3.14. Use *onexc* instead. (Contributed by Irit Katriel in :gh:`102828`.)
|
use *onexc* instead. (Contributed by Irit Katriel in :gh:`102828`.)
|
||||||
|
|
||||||
* :mod:`sqlite3`:
|
* :mod:`sqlite3`:
|
||||||
|
|
||||||
|
|
|
@ -722,10 +722,6 @@ def rmtree(path, ignore_errors=False, onerror=None, *, onexc=None, dir_fd=None):
|
||||||
If both onerror and onexc are set, onerror is ignored and onexc is used.
|
If both onerror and onexc are set, onerror is ignored and onexc is used.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if onerror is not None:
|
|
||||||
warnings.warn("onerror argument is deprecated, use onexc instead",
|
|
||||||
DeprecationWarning, stacklevel=2)
|
|
||||||
|
|
||||||
sys.audit("shutil.rmtree", path, dir_fd)
|
sys.audit("shutil.rmtree", path, dir_fd)
|
||||||
if ignore_errors:
|
if ignore_errors:
|
||||||
def onexc(*args):
|
def onexc(*args):
|
||||||
|
|
|
@ -209,7 +209,6 @@ class TestRmTree(BaseTest, unittest.TestCase):
|
||||||
errors = []
|
errors = []
|
||||||
def onerror(*args):
|
def onerror(*args):
|
||||||
errors.append(args)
|
errors.append(args)
|
||||||
with self.assertWarns(DeprecationWarning):
|
|
||||||
shutil.rmtree(link, onerror=onerror)
|
shutil.rmtree(link, onerror=onerror)
|
||||||
self.assertEqual(len(errors), 1)
|
self.assertEqual(len(errors), 1)
|
||||||
self.assertIs(errors[0][0], os.path.islink)
|
self.assertIs(errors[0][0], os.path.islink)
|
||||||
|
@ -271,7 +270,6 @@ class TestRmTree(BaseTest, unittest.TestCase):
|
||||||
errors = []
|
errors = []
|
||||||
def onerror(*args):
|
def onerror(*args):
|
||||||
errors.append(args)
|
errors.append(args)
|
||||||
with self.assertWarns(DeprecationWarning):
|
|
||||||
shutil.rmtree(link, onerror=onerror)
|
shutil.rmtree(link, onerror=onerror)
|
||||||
self.assertEqual(len(errors), 1)
|
self.assertEqual(len(errors), 1)
|
||||||
self.assertIs(errors[0][0], os.path.islink)
|
self.assertIs(errors[0][0], os.path.islink)
|
||||||
|
@ -341,7 +339,6 @@ class TestRmTree(BaseTest, unittest.TestCase):
|
||||||
errors = []
|
errors = []
|
||||||
def onerror(*args):
|
def onerror(*args):
|
||||||
errors.append(args)
|
errors.append(args)
|
||||||
with self.assertWarns(DeprecationWarning):
|
|
||||||
shutil.rmtree(filename, onerror=onerror)
|
shutil.rmtree(filename, onerror=onerror)
|
||||||
self.assertEqual(len(errors), 2)
|
self.assertEqual(len(errors), 2)
|
||||||
self.assertIs(errors[0][0], os.scandir)
|
self.assertIs(errors[0][0], os.scandir)
|
||||||
|
@ -411,7 +408,6 @@ class TestRmTree(BaseTest, unittest.TestCase):
|
||||||
self.addCleanup(os.chmod, self.child_file_path, old_child_file_mode)
|
self.addCleanup(os.chmod, self.child_file_path, old_child_file_mode)
|
||||||
self.addCleanup(os.chmod, self.child_dir_path, old_child_dir_mode)
|
self.addCleanup(os.chmod, self.child_dir_path, old_child_dir_mode)
|
||||||
|
|
||||||
with self.assertWarns(DeprecationWarning):
|
|
||||||
shutil.rmtree(TESTFN, onerror=self.check_args_to_onerror)
|
shutil.rmtree(TESTFN, onerror=self.check_args_to_onerror)
|
||||||
# Test whether onerror has actually been called.
|
# Test whether onerror has actually been called.
|
||||||
self.assertEqual(self.errorState, 3,
|
self.assertEqual(self.errorState, 3,
|
||||||
|
@ -538,7 +534,6 @@ class TestRmTree(BaseTest, unittest.TestCase):
|
||||||
self.addCleanup(os.chmod, self.child_file_path, old_child_file_mode)
|
self.addCleanup(os.chmod, self.child_file_path, old_child_file_mode)
|
||||||
self.addCleanup(os.chmod, self.child_dir_path, old_child_dir_mode)
|
self.addCleanup(os.chmod, self.child_dir_path, old_child_dir_mode)
|
||||||
|
|
||||||
with self.assertWarns(DeprecationWarning):
|
|
||||||
shutil.rmtree(TESTFN, onerror=onerror, onexc=onexc)
|
shutil.rmtree(TESTFN, onerror=onerror, onexc=onexc)
|
||||||
self.assertTrue(onexc_called)
|
self.assertTrue(onexc_called)
|
||||||
self.assertFalse(onerror_called)
|
self.assertFalse(onerror_called)
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Remove deprecation error on passing ``onerror`` to :func:`shutil.rmtree`.
|
Loading…
Add table
Add a link
Reference in a new issue