Skip to content

bpo-33123: pathlib: Add missing_ok parameter to Path.unlink #6191

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

Merged
merged 2 commits into from
May 15, 2019

Conversation

rbu
Copy link
Contributor

@rbu rbu commented Mar 22, 2018

Similarly to how several pathlib file creation functions have an "exists_ok" parameter, we should introduce "missing_ok" that makes removal functions not raise an exception when a file or directory is already absent. IMHO, this should cover Path.unlink and Path.rmdir. Note, Path.resolve() has a "strict" parameter since 3.6 that does the same thing. Naming this of this new parameter tries to be consistent with the "exists_ok" parameter as that is more explicit about what it does (as opposed to "strict").

https://bugs.python.org/issue33123

@the-knights-who-say-ni
Copy link

Hello, and thanks for your contribution!

I'm a bot set up to make sure that the project can legally accept your contribution by verifying you have signed the PSF contributor agreement (CLA).

Unfortunately our records indicate you have not signed the CLA. For legal reasons we need you to sign this before we can look at your contribution. Please follow the steps outlined in the CPython devguide to rectify this issue.

Thanks again to your contribution and we look forward to looking at it!

@rbu rbu force-pushed the pathlib-unlink-missing-ok branch from 2e2506a to 6d6f2e9 Compare March 22, 2018 18:14
@rbu
Copy link
Contributor Author

rbu commented Mar 22, 2018

CLA is signed and submitted.

@serhiy-storchaka serhiy-storchaka added type-feature A feature request or enhancement and removed CLA not signed labels Mar 27, 2018
@@ -1627,6 +1627,11 @@ def test_unlink(self):
self.assertFileNotFound(p.stat)
self.assertFileNotFound(p.unlink)

def test_unlink_missing_ok(self):
p = self.cls(BASE) / 'fileMissing'
Copy link

@amirouche amirouche Apr 3, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's worth changing the name of the file to something sort of explicit such as fileMissing. I'd rather not surprise the reader and use what seems the default in the tests file ie. fileA here too.

WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. fileA actually exists, but I changed to fileAAA which seems to be used for a non-existing file in other tests.

@rbu rbu force-pushed the pathlib-unlink-missing-ok branch from 6d6f2e9 to 68d5edb Compare April 9, 2018 08:54
@rbu rbu force-pushed the pathlib-unlink-missing-ok branch from 68d5edb to 4277aab Compare April 9, 2018 14:59
@csabella csabella requested a review from pitrou May 14, 2019 19:11
Copy link
Member

@pitrou pitrou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A simple enough addition. LGTM.

@miss-islington
Copy link
Contributor

@rbu: Status check is done, and it's a success ✅ .

@miss-islington miss-islington merged commit d9e006b into python:master May 15, 2019
@csabella
Copy link
Contributor

Thank you, @rbu, for the PR and thank you, @pitrou, for the review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-feature A feature request or enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants