mirror of
https://github.com/python/cpython.git
synced 2025-07-29 14:15:07 +00:00
[3.13] GH-119113: Raise TypeError
from pathlib.PurePath.with_suffix(None)
(GH-119124) (#119183)
Restore behaviour from 3.12 when `path.with_suffix(None)` is called.
(cherry picked from commit 3c28510b98
)
Co-authored-by: Barney Gale <barney.gale@gmail.com>
This commit is contained in:
parent
fdc50bac16
commit
27b61c17a1
3 changed files with 9 additions and 7 deletions
|
@ -225,15 +225,13 @@ class PurePathBase:
|
|||
string, remove the suffix from the path.
|
||||
"""
|
||||
stem = self.stem
|
||||
if not suffix:
|
||||
return self.with_name(stem)
|
||||
elif not stem:
|
||||
if not stem:
|
||||
# If the stem is empty, we can't make the suffix non-empty.
|
||||
raise ValueError(f"{self!r} has an empty name")
|
||||
elif suffix.startswith('.') and len(suffix) > 1:
|
||||
return self.with_name(stem + suffix)
|
||||
else:
|
||||
elif suffix and not (suffix.startswith('.') and len(suffix) > 1):
|
||||
raise ValueError(f"Invalid suffix {suffix!r}")
|
||||
else:
|
||||
return self.with_name(stem + suffix)
|
||||
|
||||
def relative_to(self, other, *, walk_up=False):
|
||||
"""Return the relative path to another path identified by the passed
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue