Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-112645: remove deprecation warning for use of onerror in shutil.rmtree #112659

Merged
merged 5 commits into from
Dec 3, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 3 additions & 4 deletions Doc/whatsnew/3.12.rst
Original file line number Diff line number Diff line change
Expand Up @@ -838,8 +838,7 @@ shutil

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

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

* :mod:`shutil`: The *onerror* argument of :func:`shutil.rmtree` is deprecated and will be removed
in Python 3.14. Use *onexc* instead. (Contributed by Irit Katriel in :gh:`102828`.)
* :mod:`shutil`: The *onerror* argument of :func:`shutil.rmtree` is deprecated,
iritkatriel marked this conversation as resolved.
Show resolved Hide resolved
use *onexc* instead. (Contributed by Irit Katriel in :gh:`102828`.)

* :mod:`sqlite3`:

Expand Down
5 changes: 0 additions & 5 deletions Lib/shutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -721,11 +721,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 onerror is not None:
import warnings
warnings.warn("onerror argument is deprecated, use onexc instead",
DeprecationWarning, stacklevel=2)

sys.audit("shutil.rmtree", path, dir_fd)
if ignore_errors:
def onexc(*args):
Expand Down
15 changes: 5 additions & 10 deletions Lib/test/test_shutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,7 @@ def test_rmtree_fails_on_symlink_onerror(self):
errors = []
def onerror(*args):
errors.append(args)
with self.assertWarns(DeprecationWarning):
shutil.rmtree(link, onerror=onerror)
shutil.rmtree(link, onerror=onerror)
self.assertEqual(len(errors), 1)
self.assertIs(errors[0][0], os.path.islink)
self.assertEqual(errors[0][1], link)
Expand Down Expand Up @@ -270,8 +269,7 @@ def test_rmtree_fails_on_junctions_onerror(self):
errors = []
def onerror(*args):
errors.append(args)
with self.assertWarns(DeprecationWarning):
shutil.rmtree(link, onerror=onerror)
shutil.rmtree(link, onerror=onerror)
self.assertEqual(len(errors), 1)
self.assertIs(errors[0][0], os.path.islink)
self.assertEqual(errors[0][1], link)
Expand Down Expand Up @@ -340,8 +338,7 @@ def test_rmtree_errors_onerror(self):
errors = []
def onerror(*args):
errors.append(args)
with self.assertWarns(DeprecationWarning):
shutil.rmtree(filename, onerror=onerror)
shutil.rmtree(filename, onerror=onerror)
self.assertEqual(len(errors), 2)
self.assertIs(errors[0][0], os.scandir)
self.assertEqual(errors[0][1], filename)
Expand Down Expand Up @@ -410,8 +407,7 @@ def test_on_error(self):
self.addCleanup(os.chmod, self.child_file_path, old_child_file_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.
self.assertEqual(self.errorState, 3,
"Expected call to onerror function did not happen.")
Expand Down Expand Up @@ -537,8 +533,7 @@ def onexc(*args):
self.addCleanup(os.chmod, self.child_file_path, old_child_file_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.assertFalse(onerror_called)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Remove deprecation error on passing ``onerror`` to :func:`shutil.rmtree`.