Skip to content

Commit f5965c2

Browse files
authored
[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 97857ac)
1 parent b3b2706 commit f5965c2

File tree

4 files changed

+9
-18
lines changed

4 files changed

+9
-18
lines changed

Doc/whatsnew/3.12.rst

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -838,8 +838,7 @@ shutil
838838

839839
* :func:`shutil.rmtree` now accepts a new argument *onexc* which is an
840840
error handler like *onerror* but which expects an exception instance
841-
rather than a *(typ, val, tb)* triplet. *onerror* is deprecated and
842-
will be removed in Python 3.14.
841+
rather than a *(typ, val, tb)* triplet. *onerror* is deprecated.
843842
(Contributed by Irit Katriel in :gh:`102828`.)
844843

845844
* :func:`shutil.which` now consults the *PATHEXT* environment variable to
@@ -1261,8 +1260,8 @@ Deprecated
12611260
:mod:`concurrent.futures` the fix is to use a different
12621261
:mod:`multiprocessing` start method such as ``"spawn"`` or ``"forkserver"``.
12631262

1264-
* :mod:`shutil`: The *onerror* argument of :func:`shutil.rmtree` is deprecated and will be removed
1265-
in Python 3.14. Use *onexc* instead. (Contributed by Irit Katriel in :gh:`102828`.)
1263+
* :mod:`shutil`: The *onerror* argument of :func:`shutil.rmtree` is deprecated;
1264+
use *onexc* instead. (Contributed by Irit Katriel in :gh:`102828`.)
12661265

12671266
* :mod:`sqlite3`:
12681267

Lib/shutil.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -722,10 +722,6 @@ def rmtree(path, ignore_errors=False, onerror=None, *, onexc=None, dir_fd=None):
722722
If both onerror and onexc are set, onerror is ignored and onexc is used.
723723
"""
724724

725-
if onerror is not None:
726-
warnings.warn("onerror argument is deprecated, use onexc instead",
727-
DeprecationWarning, stacklevel=2)
728-
729725
sys.audit("shutil.rmtree", path, dir_fd)
730726
if ignore_errors:
731727
def onexc(*args):

Lib/test/test_shutil.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,7 @@ def test_rmtree_fails_on_symlink_onerror(self):
209209
errors = []
210210
def onerror(*args):
211211
errors.append(args)
212-
with self.assertWarns(DeprecationWarning):
213-
shutil.rmtree(link, onerror=onerror)
212+
shutil.rmtree(link, onerror=onerror)
214213
self.assertEqual(len(errors), 1)
215214
self.assertIs(errors[0][0], os.path.islink)
216215
self.assertEqual(errors[0][1], link)
@@ -271,8 +270,7 @@ def test_rmtree_fails_on_junctions_onerror(self):
271270
errors = []
272271
def onerror(*args):
273272
errors.append(args)
274-
with self.assertWarns(DeprecationWarning):
275-
shutil.rmtree(link, onerror=onerror)
273+
shutil.rmtree(link, onerror=onerror)
276274
self.assertEqual(len(errors), 1)
277275
self.assertIs(errors[0][0], os.path.islink)
278276
self.assertEqual(errors[0][1], link)
@@ -341,8 +339,7 @@ def test_rmtree_errors_onerror(self):
341339
errors = []
342340
def onerror(*args):
343341
errors.append(args)
344-
with self.assertWarns(DeprecationWarning):
345-
shutil.rmtree(filename, onerror=onerror)
342+
shutil.rmtree(filename, onerror=onerror)
346343
self.assertEqual(len(errors), 2)
347344
self.assertIs(errors[0][0], os.scandir)
348345
self.assertEqual(errors[0][1], filename)
@@ -411,8 +408,7 @@ def test_on_error(self):
411408
self.addCleanup(os.chmod, self.child_file_path, old_child_file_mode)
412409
self.addCleanup(os.chmod, self.child_dir_path, old_child_dir_mode)
413410

414-
with self.assertWarns(DeprecationWarning):
415-
shutil.rmtree(TESTFN, onerror=self.check_args_to_onerror)
411+
shutil.rmtree(TESTFN, onerror=self.check_args_to_onerror)
416412
# Test whether onerror has actually been called.
417413
self.assertEqual(self.errorState, 3,
418414
"Expected call to onerror function did not happen.")
@@ -538,8 +534,7 @@ def onexc(*args):
538534
self.addCleanup(os.chmod, self.child_file_path, old_child_file_mode)
539535
self.addCleanup(os.chmod, self.child_dir_path, old_child_dir_mode)
540536

541-
with self.assertWarns(DeprecationWarning):
542-
shutil.rmtree(TESTFN, onerror=onerror, onexc=onexc)
537+
shutil.rmtree(TESTFN, onerror=onerror, onexc=onexc)
543538
self.assertTrue(onexc_called)
544539
self.assertFalse(onerror_called)
545540

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Remove deprecation error on passing ``onerror`` to :func:`shutil.rmtree`.

0 commit comments

Comments
 (0)