@@ -530,10 +530,10 @@ Pure paths provide the following methods and properties:
530
530
unintended effects.
531
531
532
532
533
- .. method :: PurePath.joinpath(*other )
533
+ .. method :: PurePath.joinpath(*pathsegments )
534
534
535
535
Calling this method is equivalent to combining the path with each of
536
- the * other * arguments in turn::
536
+ the given * pathsegments * in turn::
537
537
538
538
>>> PurePosixPath('/etc').joinpath('passwd')
539
539
PurePosixPath('/etc/passwd')
@@ -680,6 +680,30 @@ Pure paths provide the following methods and properties:
680
680
PureWindowsPath('README')
681
681
682
682
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
+
683
707
.. _concrete-paths :
684
708
685
709
0 commit comments