This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Add PurePath.with_stem()
Type: enhancement Stage: resolved
Components: Library (Lib) Versions: Python 3.9
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: brett.cannon, pitrou, timhoffm, tinyaoqi
Priority: normal Keywords: patch

Created on 2020-04-02 00:40 by timhoffm, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 19295 merged timhoffm, 2020-04-02 01:31
Messages (4)
msg365540 - (view) Author: Tim Hoffmann (timhoffm) * Date: 2020-04-02 00:40
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)
msg365608 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2020-04-02 17:46
I personally would rather not add more methods that are doing simple string manipulations.
msg366785 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2020-04-19 15:29
New changeset 8aea4b3605059e243f1827d9328d6fc8d698c0a7 by Tim Hoffmann in branch 'master':
bpo-40148: Add PurePath.with_stem() (GH-19295)
https://github.com/python/cpython/commit/8aea4b3605059e243f1827d9328d6fc8d698c0a7
msg383834 - (view) Author: Qi Yao (tinyaoqi) Date: 2020-12-27 01:42
In Pathlib, we have functions "with_name()""with_stem()""with_suffix()" to modify the file name in the path.

In issue21798:"Allow adding Path or str to Path", it actually also want to modify the file name, that is "appand string to file name".

if with_stem() more cumbersome as:
path.with_name(path.stem + '_v2' + path.suffix)

why not have a function with_xxxx() more cumbersome as:
path.with_name(path.name + "_name.dat")
History
Date User Action Args
2022-04-11 14:59:28adminsetgithub: 84329
2020-12-27 01:42:41tinyaoqisetnosy: + tinyaoqi
messages: + msg383834
2020-04-19 15:30:07pitrousetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2020-04-19 15:29:56pitrousetmessages: + msg366785
2020-04-02 17:46:11brett.cannonsetnosy: + brett.cannon
messages: + msg365608
2020-04-02 05:44:21SilentGhostsetnosy: + pitrou

type: enhancement
versions: + Python 3.9
2020-04-02 01:31:56timhoffmsetkeywords: + patch
stage: patch review
pull_requests: + pull_request18654
2020-04-02 00:40:24timhoffmcreate