Skip to content

bpo-40148 Add PurePath.with_stem()#19295

Merged
pitrou merged 2 commits into
python:masterfrom
timhoffm:purepath-with_stem
Apr 19, 2020
Merged

bpo-40148 Add PurePath.with_stem()#19295
pitrou merged 2 commits into
python:masterfrom
timhoffm:purepath-with_stem

Conversation

@timhoffm

@timhoffm timhoffm commented Apr 2, 2020

Copy link
Copy Markdown
Contributor

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

@pitrou pitrou left a comment

Copy link
Copy Markdown
Member

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.

Comment thread Doc/library/pathlib.rst Outdated

Copy link
Copy Markdown
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
Copy Markdown
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

@pitrou pitrou left a comment

Copy link
Copy Markdown
Member

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.

Comment thread Doc/library/pathlib.rst Outdated

Copy link
Copy Markdown
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
Copy Markdown

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
Copy Markdown
Contributor Author

I have made the requested changes; please review again.

@bedevere-bot

Copy link
Copy Markdown

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