Skip to content

bpo-40148 Add PurePath.with_stem() #19295

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
Apr 19, 2020
Merged

Conversation

timhoffm
Copy link
Contributor

@timhoffm 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 pitrou left a comment

Choose a reason for hiding this comment

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

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

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

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.

@timhoffm timhoffm force-pushed the purepath-with_stem branch from 2996ed3 to 327c347 Compare April 16, 2020 23:53
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.

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

Choose a reason for hiding this comment

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

"stem" not "step"

@bedevere-bot
Copy link

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.

@timhoffm timhoffm force-pushed the purepath-with_stem branch from 327c347 to eac93d0 Compare April 19, 2020 14:11
@timhoffm
Copy link
Contributor Author

I have made the requested changes; please review again.

@bedevere-bot
Copy link

Thanks for making the requested changes!

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

@bedevere-bot bedevere-bot requested a review from pitrou April 19, 2020 15:25
@pitrou pitrou merged commit 8aea4b3 into python:master Apr 19, 2020
@timhoffm timhoffm deleted the purepath-with_stem branch April 19, 2020 15:52
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.

4 participants