summaryrefslogtreecommitdiffstats
path: root/Doc/library/pathlib.rst
diff options
context:
space:
mode:
Diffstat (limited to 'Doc/library/pathlib.rst')
-rw-r--r--Doc/library/pathlib.rst28
1 files changed, 26 insertions, 2 deletions
diff --git a/Doc/library/pathlib.rst b/Doc/library/pathlib.rst
index 1411812..5ffa33d 100644
--- a/Doc/library/pathlib.rst
+++ b/Doc/library/pathlib.rst
@@ -530,10 +530,10 @@ Pure paths provide the following methods and properties:
unintended effects.
-.. method:: PurePath.joinpath(*other)
+.. method:: PurePath.joinpath(*pathsegments)
Calling this method is equivalent to combining the path with each of
- the *other* arguments in turn::
+ the given *pathsegments* in turn::
>>> PurePosixPath('/etc').joinpath('passwd')
PurePosixPath('/etc/passwd')
@@ -680,6 +680,30 @@ Pure paths provide the following methods and properties:
PureWindowsPath('README')
+.. method:: PurePath.with_segments(*pathsegments)
+
+ Create a new path object of the same type by combining the given
+ *pathsegments*. This method is called whenever a derivative path is created,
+ such as from :attr:`parent` and :meth:`relative_to`. Subclasses may
+ override this method to pass information to derivative paths, for example::
+
+ from pathlib import PurePosixPath
+
+ class MyPath(PurePosixPath):
+ def __init__(self, *pathsegments, session_id):
+ super().__init__(*pathsegments)
+ self.session_id = session_id
+
+ def with_segments(self, *pathsegments):
+ return type(self)(*pathsegments, session_id=self.session_id)
+
+ etc = MyPath('/etc', session_id=42)
+ hosts = etc / 'hosts'
+ print(hosts.session_id) # 42
+
+ .. versionadded:: 3.12
+
+
.. _concrete-paths: