GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-102828: add onexc arg to shutil.rmtree. Deprecate onerror. by iritkatriel · Pull Request #102829 · python/cpython

Conversation

@iritkatriel

@iritkatriel iritkatriel commented Mar 19, 2023 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

onexc expects an exception instead of exc_info. This is part of the larger effort to move on from exc_info.

Fixes #102828.

  • Issue: add option for error callback of to shutil.rmtree to accept exception rather than exc_info #102828

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@iritkatriel
pythongh-102828: add onexc arg to shutil.rmtree. Deprecate onerror.
86a1cea
@bedevere-bot bedevere-bot mentioned this pull request Mar 19, 2023
add option for error callback of to shutil.rmtree to accept exception rather than exc_info #102828
Closed
@bedevere-bot bedevere-bot added the awaiting core review label Mar 19, 2023
@iritkatriel
fix typo
03fa88f
@iritkatriel iritkatriel added the stdlib Standard Library Python modules in the Lib/ directory label Mar 19, 2023
@iritkatriel
iritkatriel requested a review from giampaolo March 19, 2023 15:44
@giampaolo

giampaolo commented Mar 19, 2023 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

I like the idea in principle, but existing code using onerror will stop working, because onerror arg is accepted but silently ignored. I think a retro-compatible solution to this could be to call onexc AND onerror for a certain period of time.

I'm not sure what's the current policy re. deprecations, but I suppose there can be a transitional time (2 releases? 3?) during which using onerror arg results in DeprecationWarning and then it's finally removed. Something like (not tested):

try:
    ...
except OSError as err:
    if onerror is not None:
        warnings.warn("'onerror' argument is deprecated and will be removed in XXX. Use 'onexc' argument instead.", 
                      DeprecationWarning)
        onerror(..., ..., sys.exc_info())
    if onexc is not None:
        onerror(..., ..., err)
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@iritkatriel

iritkatriel commented Mar 19, 2023

Copy link
Copy Markdown
Member Author

existing code using onerror will stop working

It will still work, because onerror gets wrapped by onexc in Lib/shutil.py:708-714.

Note that I didn't remove any tests, so all previous functionality is still there.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@giampaolo

giampaolo commented Mar 19, 2023

Copy link
Copy Markdown
Contributor

Oh you're right sorry. I misread your patch.

iritkatriel reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

giampaolo
giampaolo requested changes Mar 19, 2023
View reviewed changes
Comment thread Doc/library/shutil.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Lib/shutil.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-bot bedevere-bot added awaiting changes and removed awaiting core review labels Mar 19, 2023
@bedevere-bot

bedevere-bot commented Mar 19, 2023

Copy link
Copy Markdown

When you're done making the requested changes, leave the comment: I have made the requested changes; please review again.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

iritkatriel added 2 commits March 19, 2023 17:29
@iritkatriel
fix typo
7960670
@iritkatriel
e --> err
f5a3aa7
iritkatriel
iritkatriel commented Mar 19, 2023
View reviewed changes
Comment thread Lib/shutil.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

@iritkatriel

iritkatriel commented Mar 19, 2023

Copy link
Copy Markdown
Member Author

When you're done making the requested changes, leave the comment: I have made the requested changes; please review again.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-bot bedevere-bot added awaiting change review and removed awaiting changes labels Mar 19, 2023
@bedevere-bot

bedevere-bot commented Mar 19, 2023

Copy link
Copy Markdown

Thanks for making the requested changes!

@giampaolo: please review the changes made to this pull request.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-bot
bedevere-bot requested a review from giampaolo March 19, 2023 17:35
giampaolo
giampaolo approved these changes Mar 19, 2023
View reviewed changes
@bedevere-bot bedevere-bot added awaiting merge and removed awaiting change review labels Mar 19, 2023
@iritkatriel
iritkatriel merged commit d51a6dc into python:main Mar 19, 2023
@bedevere-bot bedevere-bot removed the awaiting merge label Mar 19, 2023
@bedevere-bot

bedevere-bot commented Mar 19, 2023

Copy link
Copy Markdown

⚠️⚠️⚠️ Buildbot failure ⚠️⚠️⚠️

Hi! The buildbot wasm32-wasi 3.x has failed when building commit d51a6dc.

What do you need to do:

  1. Don't panic.
  2. Check the buildbot page in the devguide if you don't know what the buildbots are or how they work.
  3. Go to the page of the buildbot that failed (https://buildbot.python.org/all/#builders/1046/builds/1597) and take a look at the build logs.
  4. Check if the failure is related to this commit (d51a6dc) or if it is a false positive.
  5. If the failure is related to this commit, please, reflect that on the issue and make a new Pull Request with a fix.

You can take a look at the buildbot page here:

https://buildbot.python.org/all/#builders/1046/builds/1597

Failed tests:

  • test_shutil

Failed subtests:

  • test_both_onerror_and_onexc - test.test_shutil.TestRmTree.test_both_onerror_and_onexc

Summary of the results of the build (if available):

== Tests result: FAILURE ==

325 tests OK.

10 slowest tests:

  • test_compile: 5 min 40 sec
  • test_math: 1 min 13 sec
  • test_tokenize: 48.5 sec
  • test_lib2to3: 40.6 sec
  • test_unparse: 33.8 sec
  • test_capi: 24.1 sec
  • test_hashlib: 24.1 sec
  • test_unicodedata: 18.5 sec
  • test_statistics: 13.9 sec
  • test_pickle: 13.7 sec

1 test failed:
test_shutil

107 tests skipped:
test__xxinterpchannels test__xxsubinterpreters test_asyncgen
test_asyncio test_bz2 test_clinic test_cmd_line
test_concurrent_futures test_contextlib_async test_ctypes
test_curses test_dbm_gnu test_dbm_ndbm test_devpoll test_doctest
test_docxmlrpc test_dtrace test_embed test_epoll test_faulthandler
test_fcntl test_file_eintr test_fork1 test_ftplib test_gdb
test_grp test_gzip test_httplib test_httpservers test_idle
test_imaplib test_interpreters test_ioctl test_kqueue
test_launcher test_lzma test_mailbox test_mmap test_msilib
test_multiprocessing_fork test_multiprocessing_forkserver
test_multiprocessing_main_handling test_multiprocessing_spawn
test_nis test_openpty test_ossaudiodev test_pdb test_peg_generator
test_perf_profiler test_pipes test_poll test_poplib test_pty
test_pwd test_queue test_readline test_regrtest test_repl
test_resource test_select test_selectors test_smtplib test_smtpnet
test_socket test_socketserver test_spwd test_sqlite3 test_ssl
test_stable_abi_ctypes test_startfile test_subprocess
test_sys_settrace test_syslog test_tcl test_telnetlib test_thread
test_threadedtempfile test_threading test_threading_local test_tix
test_tkinter test_tools test_ttk test_ttk_textonly test_turtle
test_urllib test_urllib2 test_urllib2_localnet test_urllib2net
test_urllib_response test_urllibnet test_venv test_wait3
test_wait4 test_webbrowser test_winconsoleio test_winreg
test_winsound test_wmi test_wsgiref test_xmlrpc test_xmlrpc_net
test_xxlimited test_zipfile64 test_zipimport_support test_zlib
test_zoneinfo
0:08:09 load avg: 1.99
0:08:09 load avg: 1.99 Re-running failed tests is not supported with --python host runner option.

Total duration: 8 min 9 sec

Click to see traceback logs
Traceback (most recent call last):
  File "/Lib/test/test_shutil.py", line 532, in test_both_onerror_and_onexc
    self.assertTrue(onexc_called)
AssertionError: False is not true


Traceback (most recent call last):
  File "/Lib/shutil.py", line 762, in rmtree
    return _rmtree_unsafe(path, onexc)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Lib/shutil.py", line 583, in _rmtree_unsafe
    onexc(os.scandir, path, err)
  File "/Lib/shutil.py", line 580, in _rmtree_unsafe
    with os.scandir(path) as scandir_it:
         ^^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 44] No such file or directory: '@test_42_tmpæ'
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-bot

bedevere-bot commented Mar 19, 2023

Copy link
Copy Markdown

⚠️⚠️⚠️ Buildbot failure ⚠️⚠️⚠️

Hi! The buildbot AMD64 Debian root 3.x has failed when building commit d51a6dc.

What do you need to do:

  1. Don't panic.
  2. Check the buildbot page in the devguide if you don't know what the buildbots are or how they work.
  3. Go to the page of the buildbot that failed (https://buildbot.python.org/all/#builders/345/builds/4352) and take a look at the build logs.
  4. Check if the failure is related to this commit (d51a6dc) or if it is a false positive.
  5. If the failure is related to this commit, please, reflect that on the issue and make a new Pull Request with a fix.

You can take a look at the buildbot page here:

https://buildbot.python.org/all/#builders/345/builds/4352

Failed tests:

  • test_shutil

Failed subtests:

  • test_both_onerror_and_onexc - test.test_shutil.TestRmTree.test_both_onerror_and_onexc

Summary of the results of the build (if available):

== Tests result: FAILURE then FAILURE ==

411 tests OK.

10 slowest tests:

  • test_tools: 10 min 20 sec
  • test_math: 5 min 20 sec
  • test_multiprocessing_spawn: 3 min 57 sec
  • test_compile: 3 min 33 sec
  • test_concurrent_futures: 2 min 56 sec
  • test_asyncio: 2 min 40 sec
  • test_tokenize: 2 min 6 sec
  • test_unparse: 2 min 6 sec
  • test_lib2to3: 1 min 52 sec
  • test_capi: 1 min 52 sec

1 test failed:
test_shutil

21 tests skipped:
test_dbm_ndbm test_devpoll test_gdb test_idle test_ioctl
test_kqueue test_launcher test_msilib test_peg_generator
test_startfile test_tcl test_tix test_tkinter test_ttk
test_ttk_textonly test_turtle test_winconsoleio test_winreg
test_winsound test_wmi test_zipfile64

1 re-run test:
test_shutil

Total duration: 39 min 34 sec

Click to see traceback logs
Traceback (most recent call last):
  File "/root/buildarea/3.x.angelico-debian-amd64/build/Lib/shutil.py", line 725, in rmtree
    onexc(os.lstat, path, err)
  File "/root/buildarea/3.x.angelico-debian-amd64/build/Lib/shutil.py", line 723, in rmtree
    orig_st = os.lstat(path, dir_fd=dir_fd)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: '@test_3079655_tmpæ'


Traceback (most recent call last):
  File "/root/buildarea/3.x.angelico-debian-amd64/build/Lib/shutil.py", line 725, in rmtree
    onexc(os.lstat, path, err)
  File "/root/buildarea/3.x.angelico-debian-amd64/build/Lib/shutil.py", line 723, in rmtree
    orig_st = os.lstat(path, dir_fd=dir_fd)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: '@test_3084007_tmpæ'


Traceback (most recent call last):
  File "/root/buildarea/3.x.angelico-debian-amd64/build/Lib/test/test_shutil.py", line 532, in test_both_onerror_and_onexc
    self.assertTrue(onexc_called)
AssertionError: False is not true
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@giampaolo

giampaolo commented Mar 19, 2023

Copy link
Copy Markdown
Contributor

@iritkatriel looks like this broke some build bots.

Traceback (most recent call last):
  File "/root/buildarea/3.x.angelico-debian-amd64/build/Lib/shutil.py", line 725, in rmtree
    onexc(os.lstat, path, err)
  File "/root/buildarea/3.x.angelico-debian-amd64/build/Lib/shutil.py", line 723, in rmtree
    orig_st = os.lstat(path, dir_fd=dir_fd)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: '@test_3079655_tmpæ'


Traceback (most recent call last):
  File "/root/buildarea/3.x.angelico-debian-amd64/build/Lib/shutil.py", line 725, in rmtree
    onexc(os.lstat, path, err)
  File "/root/buildarea/3.x.angelico-debian-amd64/build/Lib/shutil.py", line 723, in rmtree
    orig_st = os.lstat(path, dir_fd=dir_fd)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: '@test_3084007_tmpæ'


Traceback (most recent call last):
  File "/root/buildarea/3.x.angelico-debian-amd64/build/Lib/test/test_shutil.py", line 532, in test_both_onerror_and_onexc
    self.assertTrue(onexc_called)
AssertionError: False is not true
iritkatriel reacted with eyes emoji
All reactions
  • 👀 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@iritkatriel

iritkatriel commented Mar 19, 2023

Copy link
Copy Markdown
Member Author

I see what I did - I copied part of this test from another test, but I didn't copy the skip instructions that make it not run where it doesn't work. Will fix.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@terryjreedy

terryjreedy commented Mar 19, 2023

Copy link
Copy Markdown
Member

Ignore my experiment with the 1st buildbot report.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Fidget-Spinner pushed a commit to Fidget-Spinner/cpython that referenced this pull request Mar 27, 2023
@iritkatriel @Fidget-Spinner
pythongh-102828: add onexc arg to shutil.rmtree. Deprecate onerror. (p…
c8e62e7
…ython#102829)
@barneygale

barneygale commented Apr 3, 2023 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Hey, why does onexc accept three arguments (function, path, exc) rather than just the exception?

If it accepted only one argument, then:

  1. It would match the onerror argument to os.walk() and os.fwalk()
  2. Users could still get the file path that failed via exc.filename
  3. Users could still print the exception/traceback to display exactly what failed

The only thing lost would be the function value, which seems like an unreasonably detailed insight into the internals of rmtree(). In fact, rmtree() already bends the truth about the function that actually failed - for example os.path.islink is given if we fail a junction check on Windows. And no internal code looks at the value of function.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@iritkatriel

iritkatriel commented Apr 3, 2023

Copy link
Copy Markdown
Member Author

Hey, why does onexc accept three arguments (function, path, exc) rather than just the exception?

Because that's what onerror did. This PR was just about replacing exc_info by exc. Feel free to suggest additional changes in a separate issue.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@iritkatriel
iritkatriel deleted the rmtree branch April 3, 2023 17:40
@barneygale

barneygale commented Apr 3, 2023

Copy link
Copy Markdown
Contributor

Righto, thanks. I've logged #103218.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

This was referenced Apr 6, 2023
onerror now producing warnings in Python 3.12 latest alpha pypa/wheel#526
Closed
Failing (or warning?) with Python 3.12 alpha 7 gitpython-developers/GitPython#1571
Closed
warsaw pushed a commit to warsaw/cpython that referenced this pull request Apr 11, 2023
@iritkatriel @warsaw
pythongh-102828: add onexc arg to shutil.rmtree. Deprecate onerror. (p…
7f3bf06
…ython#102829)
@coderabbitai coderabbitai Bot mentioned this pull request Aug 1, 2026
feat(release): a portable release fixture and the protected-state machinery it needs (#563, #564) arbiterForge/codeArbiter#576
Merged
@coderabbitai coderabbitai Bot mentioned this pull request Sep 12, 2026
ci+test(viz): hermetic viz gate on a frozen corpus; data-gated interaction pins robbe1912/neuronav#166
Merged
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@giampaolo giampaolo giampaolo approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

stdlib Standard Library Python modules in the Lib/ directory

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

add option for error callback of to shutil.rmtree to accept exception rather than exc_info

Uh oh!

There was an error while loading. Please reload this page.

5 participants

@iritkatriel @giampaolo @bedevere-bot @terryjreedy @barneygale
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.