mirror of
https://github.com/python/cpython.git
synced 2026-01-06 07:22:09 +00:00
GH-130614: pathlib ABCs: retain original separator in with_name() (#130990)
In `pathlib.types._JoinablePath.with_name()`, retain any alternative path separator preceding the old name, rather stripping and replacing it with a primary separator. As a result, this method changes _only_ the name.
This commit is contained in:
parent
c240c2d88a
commit
ba64cc5db4
1 changed files with 3 additions and 1 deletions
|
|
@ -135,7 +135,9 @@ def with_name(self, name):
|
|||
split = self.parser.split
|
||||
if split(name)[0]:
|
||||
raise ValueError(f"Invalid name {name!r}")
|
||||
return self.with_segments(split(str(self))[0], name)
|
||||
path = str(self)
|
||||
path = path.removesuffix(split(path)[1]) + name
|
||||
return self.with_segments(path)
|
||||
|
||||
def with_stem(self, stem):
|
||||
"""Return a new path with the stem changed."""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue