Issue #20639: calling Path.with_suffix('') allows removing the suffix again.

Patch by July Tikhonov.
This commit is contained in:
Antoine Pitrou 2014-07-06 21:37:15 -04:00
parent 7084e736db
commit e50dafcd63
3 changed files with 12 additions and 4 deletions

View file

@ -759,11 +759,10 @@ 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:
f = self._flavour
if f.sep in suffix or f.altsep and f.altsep in suffix:
raise ValueError("Invalid suffix %r" % (suffix))
suffix = parts[0]
if not suffix.startswith('.'):
if suffix and not suffix.startswith('.') or suffix == '.':
raise ValueError("Invalid suffix %r" % (suffix))
name = self.name
if not name: