GH-73991: Prune `pathlib.Path.delete()` arguments by barneygale · Pull Request #123158 · python/cpython · GitHub
Skip to content

GH-73991: Prune pathlib.Path.delete() arguments - #123158

Closed
barneygale wants to merge 5 commits into
python:mainfrom
barneygale:gh-73991-streamline-delete
Closed

GH-73991: Prune pathlib.Path.delete() arguments#123158
barneygale wants to merge 5 commits into
python:mainfrom
barneygale:gh-73991-streamline-delete

Conversation

@barneygale

@barneygale barneygale commented Aug 19, 2024

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.


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

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 marked this pull request as ready for review August 20, 2024 21:56
@barneygale
barneygale requested a review from pfmoore August 20, 2024 21:58
@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

@barneygale

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.

@barneygale barneygale closed this Aug 22, 2024
barneygale added a commit to barneygale/cpython that referenced this pull request Aug 25, 2024
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 added a commit that referenced this pull request Aug 26, 2024
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

Copy link
Copy Markdown

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants