[proxy] web.archive.org← back | site home | direct (HTTPS) ↗ | proxy home | ◑ dark◐ light
/ cpython Public
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

bpo-40148 Add PurePath.with_stem() #19295

Merged
merged 2 commits into from Apr 19, 2020
Merged

Conversation

Copy link
Contributor

timhoffm commented Apr 2, 2020

Similar to PurePath.with_name() and PurePath.with_suffix() there should be a PurePath.with_stem().

A common use case would be appending something before the suffix:
path.with_stem(path.stem + '_v2')

As of now this must be written more cumbersome as:
path.with_name(path.stem + '_v2' + path.suffix)

While the implementation is just a slight modification of with_name, I still think it's justified to add this method:

  • It states the intent much clearer than meddling with_name() and suffix manually together.
  • From an API symmetry/completeness point of view, this is missing in the set of methods for modifying filenames.

https://bugs.python.org/issue40148

Copy link
Member

pitrou left a comment

This looks generally good to me, just one question.

>>> p.with_stem('final')
PureWindowsPath('c:/Downloads/final.txt')
>>> p = PureWindowsPath('c:/Downloads/pathlib.tar.gz')
>>> p.with_name('lib')
Copy link
Member

pitrou Apr 16, 2020

Choose a reason for hiding this comment

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

Surely you mean with_stem here?

Copy link
Contributor Author

timhoffm Apr 16, 2020

Choose a reason for hiding this comment

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

Yes, of course. Thanks. Fixed.

Copy link
Member

pitrou left a comment

Looks like there is a final typo. Also, can you add a NEWS entry. You can do so either on the Web using blurb-it, or from the command line using blurb.

>>> p.with_stem('final')
PureWindowsPath('c:/Downloads/final.txt')
>>> p = PureWindowsPath('c:/Downloads/pathlib.tar.gz')
>>> p.with_step('lib')
Copy link
Member

pitrou Apr 17, 2020

Choose a reason for hiding this comment

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

"stem" not "step"

Copy link

bedevere-bot commented Apr 17, 2020

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

Copy link
Contributor Author

timhoffm commented Apr 19, 2020

I have made the requested changes; please review again.

Copy link

bedevere-bot commented Apr 19, 2020

Thanks for making the requested changes!

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

bedevere-bot requested a review from pitrou Apr 19, 2020
pitrou approved these changes Apr 19, 2020
pitrou merged commit 8aea4b3 into python:master Apr 19, 2020
timhoffm deleted the purepath-with_stem branch Apr 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants