Issue #20765: Add missing documentation for PurePath.with_name() and PurePath.with_su...
authorAntoine Pitrou <solipsis@pitrou.net>
Tue, 25 Feb 2014 19:33:02 +0000 (20:33 +0100)
committerAntoine Pitrou <solipsis@pitrou.net>
Tue, 25 Feb 2014 19:33:02 +0000 (20:33 +0100)
Doc/library/pathlib.rst
Misc/NEWS

index 3aa9d4b33b6d0343a8756eaf6f3c38af105e7a1a..ec1dc4f6168cfd7e5d94d810df396a7998cebed2 100644 (file)
@@ -522,6 +522,36 @@ Pure paths provide the following methods and properties:
       ValueError: '/etc/passwd' does not start with '/usr'
 
 
+.. method:: PurePath.with_name(name)
+
+   Return a new path with the :attr:`name` changed.  If the original path
+   doesn't have a name, ValueError is raised::
+
+      >>> p = PureWindowsPath('c:/Downloads/pathlib.tar.gz')
+      >>> p.with_name('setup.py')
+      PureWindowsPath('c:/Downloads/setup.py')
+      >>> p = PureWindowsPath('c:/')
+      >>> p.with_name('setup.py')
+      Traceback (most recent call last):
+        File "<stdin>", line 1, in <module>
+        File "/home/antoine/cpython/default/Lib/pathlib.py", line 751, in with_name
+          raise ValueError("%r has an empty name" % (self,))
+      ValueError: PureWindowsPath('c:/') has an empty name
+
+
+.. 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::
+
+      >>> p = PureWindowsPath('c:/Downloads/pathlib.tar.gz')
+      >>> p.with_suffix('.bz2')
+      PureWindowsPath('c:/Downloads/pathlib.tar.bz2')
+      >>> p = PureWindowsPath('README')
+      >>> p.with_suffix('.txt')
+      PureWindowsPath('README.txt')
+
+
 .. _concrete-paths:
 
 
index 9f9c98171b492c379dd337c9a8bb9366f92a727b..b11cd2e0526f82b9c428c0b9f82bbca1adf4e286 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -17,6 +17,12 @@ Library
 - Issue #19748: On AIX, time.mktime() now raises an OverflowError for year
   outsize range [1902; 2037].
 
+Documentation
+-------------
+
+- Issue #20765: Add missing documentation for PurePath.with_name() and
+  PurePath.with_suffix().
+
 Tests
 -----