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-73991: Prune `pathlib.Path.delete()` arguments by barneygale · Pull Request #123158 · python/cpython

Conversation

@barneygale

@barneygale barneygale commented Aug 19, 2024 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor

Remove the ignore_errors and on_error arguments from Path.delete(). This functionality was carried over from shutil.rmtree(), but its design needs to be re-evaluated in its new context. Some possible alternate designs:

  • We may wish to support a missing_ok argument (like Path.unlink())
  • Or automatically chmod() and retry operations when we hit a permission error (like tempfile.TemporaryDirectory)
  • Or retry operations with a backoff (like test.support.os_helper.rmtree()),
  • Or utilise exception groups

It's best to leave our options open for now. I don't want to risk these arguments landing in 3.14 final because I got hit by a bus or something.

No news because Path.delete() remains unreleased.

  • Issue: Support moving across filesystems in pathlib.Path, as shutil.move() does #73991

📚 Documentation preview 📚: https://cpython-previews--123158.org.readthedocs.build/

Sorry, something went wrong.

Uh oh!

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

All reactions
@barneygale
pythonGH-73991: Prune pathlib.Path.delete()
3a03d81
Remove the *ignore_errors* and *on_error* arguments from `Path.delete()`.
This functionality was carried over from `shutil`, but its design needs to
be re-considered in its new context. For example, we may wish to support a
*missing_ok* argument (like `Path.unlink()`), or automatically `chmod()`
and retry operations when we hit a permission error (like
`tempfile.TemporaryDirectory`), or retry operations with a backoff (like
`test.support.os_helper.rmtree()`), or utilise exception groups, etc. It's
best to leave our options open for now.
@barneygale barneygale added skip news topic-pathlib labels Aug 19, 2024
@bedevere-app bedevere-app Bot mentioned this pull request Aug 19, 2024
Support moving across filesystems in pathlib.Path, as shutil.move() does #73991
Closed
barneygale added 3 commits August 19, 2024 21:47
@barneygale
Windows tests fixes
2420b85
@barneygale
Improve deletion of junctions
b934731
@barneygale
Junction handling tweaks
8edcabe
@barneygale
barneygale marked this pull request as ready for review August 20, 2024 21:56
@bedevere-app bedevere-app Bot added the awaiting core review label Aug 20, 2024
@barneygale
barneygale requested a review from pfmoore August 20, 2024 21:58
@barneygale
Undo unnecessary change.
229b60a
@barneygale barneygale changed the title GH-73991: Prune pathlib.Path.delete() GH-73991: Prune pathlib.Path.delete() arguments Aug 21, 2024
@pfmoore

pfmoore commented Aug 22, 2024

Copy link
Copy Markdown
Member

I can understand the logic that we omit the arguments until we're sure we have the right design, but in my experience, a directory tree delete very often needs these arguments (specifically on_error)1. Finding a read-only file partway through a directory deletion can cause the deletion to fail half-done, leaving the filesystem in a mess. And having to traverse the directory tree, either in advance or after the fact, to locate the offending file and fix the issue, can be extremely costly in a large directory structure.

To put this another way, the key benefit of on_error is to allow problems to be handled in context. Without that capability, I think I'd always advise using shutil.rmtree over Path.delete.

I'd rather defer making Path.delete public until we have the error handling sorted out, over releasing it in a state that makes it strictly worse than shutil.rmtree.

Footnotes

  1. For example, I thought that the way .git directories were created on Windows used to mean that they would always cause failures without corrective action in on_error, but when I tested just now, it looks like things might have changed there. Nevertheless, the point about fixing errors in context remains. ↩

barneygale reacted with heart emoji
All reactions
  • ❤️ 1 reaction

Sorry, something went wrong.

Uh oh!

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

@barneygale

barneygale commented Aug 22, 2024

Copy link
Copy Markdown
Contributor Author

Thanks very much, that's most helpful. I'll close this PR for now, and open a new topic on the forum (in a few weeks time) about what to do with these arguments. I'll try to make the case that the number of practical on_error implementations is limited - in general you retry the unlink() or rmdir(), possibly after a chmod() and/or a time delay - and that there might be a more pathlib-y way to expose these options.

All reactions

Sorry, something went wrong.

Uh oh!

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

@barneygale barneygale closed this Aug 22, 2024
barneygale added a commit to barneygale/cpython that referenced this pull request Aug 25, 2024
@barneygale
pythonGH-73991: Make pathlib.Path.delete() private.
a3dd339
Per feedback from Paul Moore on pythonGH-123158, it's better to defer making
`Path.delete()` public than ship it with under-designed error handling
capabilities.

We leave a remnant `_delete()` method, which is used by `move()`. Any
functionality not needed by `move()` is deleted.
@barneygale barneygale mentioned this pull request Aug 25, 2024
GH-73991: Make pathlib.Path.delete() private. #123315
Merged
barneygale added a commit that referenced this pull request Aug 26, 2024
@barneygale
GH-73991: Make pathlib.Path.delete() private. (#123315)
033d537
Per feedback from Paul Moore on GH-123158, it's better to defer making
`Path.delete()` public than ship it with under-designed error handling
capabilities.

We leave a remnant `_delete()` method, which is used by `move()`. Any
functionality not needed by `move()` is deleted.
@tjg-global

tjg-global commented Aug 27, 2024

Copy link
Copy Markdown

A tiny point, somewhat after the event. In the current shutil.rmtree the onerror callback has been deprecated in favour of a similar but different onexc. Same arguments apply as above, and I rather agree with @pfmoore ("the key benefit of on_error is to allow problems to be handled in context").

All reactions

Sorry, something went wrong.

Uh oh!

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@pfmoore pfmoore Awaiting requested review from pfmoore

Uh oh!

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

Assignees

No one assigned

Labels

awaiting core review skip news topic-pathlib

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

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

3 participants

@barneygale @pfmoore @tjg-global
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 01402520 — 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.