mirror of
https://github.com/python/cpython.git
synced 2025-10-09 08:31:26 +00:00
Issue #20111: pathlib.Path.with_suffix() now sanity checks the given suffix.
This commit is contained in:
parent
8ec15f7a92
commit
1b02da95d2
3 changed files with 28 additions and 0 deletions
|
@ -755,6 +755,12 @@ class PurePath(object):
|
|||
def with_suffix(self, suffix):
|
||||
"""Return a new path with the file suffix changed (or added, if none)."""
|
||||
# XXX if suffix is None, should the current suffix be removed?
|
||||
drv, root, parts = self._flavour.parse_parts((suffix,))
|
||||
if drv or root or len(parts) != 1:
|
||||
raise ValueError("Invalid suffix %r" % (suffix))
|
||||
suffix = parts[0]
|
||||
if not suffix.startswith('.'):
|
||||
raise ValueError("Invalid suffix %r" % (suffix))
|
||||
name = self.name
|
||||
if not name:
|
||||
raise ValueError("%r has an empty name" % (self,))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue