]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-34329: Doc'd how to remove suffix of pathlib.Path() (GH-8655)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Fri, 3 Aug 2018 21:45:20 +0000 (14:45 -0700)
committerBerker Peksag <berker.peksag@gmail.com>
Fri, 3 Aug 2018 21:45:20 +0000 (00:45 +0300)
(cherry picked from commit 46dc4e34ed8005a688d7f3512844ef227a3465f4)

Co-authored-by: Stefan Otte <stefan.otte@gmail.com>
Doc/library/pathlib.rst
Lib/pathlib.py

index 34ab3b8edf962b61d6a65ff131007723ce88fcc1..7b3c9ecc2f092da488670f4a29a34025ed11461f 100644 (file)
@@ -555,7 +555,8 @@ Pure paths provide the following methods and properties:
 .. method:: PurePath.with_suffix(suffix)
 
    Return a new path with the :attr:`suffix` changed.  If the original path
-   doesn't have a suffix, the new *suffix* is appended instead::
+   doesn't have a suffix, the new *suffix* is appended instead.  If the
+   *suffix* is an empty string, the original suffix is removed::
 
       >>> p = PureWindowsPath('c:/Downloads/pathlib.tar.gz')
       >>> p.with_suffix('.bz2')
@@ -563,6 +564,9 @@ Pure paths provide the following methods and properties:
       >>> p = PureWindowsPath('README')
       >>> p.with_suffix('.txt')
       PureWindowsPath('README.txt')
+      >>> p = PureWindowsPath('README.txt')
+      >>> p.with_suffix('')
+      PureWindowsPath('README')
 
 
 .. _concrete-paths:
index 44788c02c2f3dc29334608c94d109b1ecd17f38d..5e130110f2e8c2a0ff2903c8ec8a61d54b2d49a3 100644 (file)
@@ -823,8 +823,10 @@ class PurePath(object):
                                        self._parts[:-1] + [name])
 
     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?
+        """Return a new path with the file suffix changed.  If the path
+        has no suffix, add given suffix.  If the given suffix is an empty
+        string, remove the suffix from the path.
+        """
         f = self._flavour
         if f.sep in suffix or f.altsep and f.altsep in suffix:
             raise ValueError("Invalid suffix %r" % (suffix))