@@ -530,10 +530,10 @@ Pure paths provide the following methods and properties:
530530 unintended effects.
531531
532532
533- .. method :: PurePath.joinpath(*other )
533+ .. method :: PurePath.joinpath(*pathsegments )
534534
535535 Calling this method is equivalent to combining the path with each of
536- the * other * arguments in turn::
536+ the given * pathsegments * in turn::
537537
538538 >>> PurePosixPath('/etc').joinpath('passwd')
539539 PurePosixPath('/etc/passwd')
@@ -680,6 +680,30 @@ Pure paths provide the following methods and properties:
680680 PureWindowsPath('README')
681681
682682
683+ .. method :: PurePath.with_segments(*pathsegments)
684+
685+ Create a new path object of the same type by combining the given
686+ *pathsegments *. This method is called whenever a derivative path is created,
687+ such as from :attr: `parent ` and :meth: `relative_to `. Subclasses may
688+ override this method to pass information to derivative paths, for example::
689+
690+ from pathlib import PurePosixPath
691+
692+ class MyPath(PurePosixPath):
693+ def __init__(self, *pathsegments, session_id):
694+ super().__init__(*pathsegments)
695+ self.session_id = session_id
696+
697+ def with_segments(self, *pathsegments):
698+ return type(self)(*pathsegments, session_id=self.session_id)
699+
700+ etc = MyPath('/etc', session_id=42)
701+ hosts = etc / 'hosts'
702+ print(hosts.session_id) # 42
703+
704+ .. versionadded :: 3.12
705+
706+
683707.. _concrete-paths :
684708
685709
0 commit comments