Skip to content

Commit 7f28ed3

Browse files
committed
with_segments --> with_path
1 parent 610b0c4 commit 7f28ed3

File tree

5 files changed

+24
-24
lines changed

5 files changed

+24
-24
lines changed

Doc/library/pathlib.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -680,7 +680,7 @@ Pure paths provide the following methods and properties:
680680
PureWindowsPath('README')
681681

682682

683-
.. method:: PurePath.with_segments(*pathsegments)
683+
.. method:: PurePath.with_path(*pathsegments)
684684

685685
Create a new path object of the same type by combining the given
686686
*pathsegments*. This method is called whenever a derivative path is created,
@@ -694,7 +694,7 @@ Pure paths provide the following methods and properties:
694694
super().__init__(*args)
695695
self.session_id = session_id
696696

697-
def with_segments(self, *pathsegments):
697+
def with_path(self, *pathsegments):
698698
return type(self)(*pathsegments, session_id=self.session_id)
699699

700700
etc = MyPath('/etc', session_id=42)

Doc/whatsnew/3.12.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ pathlib
280280

281281
* Add support for subclassing :class:`pathlib.PurePath` and
282282
:class:`~pathlib.Path`, plus their Posix- and Windows-specific variants.
283-
Subclasses may override the :meth:`~pathlib.PurePath.with_segments` method
283+
Subclasses may override the :meth:`~pathlib.PurePath.with_path` method
284284
to pass information between path instances.
285285

286286
* Add :meth:`~pathlib.Path.walk` for walking the directory trees and generating

Lib/pathlib.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ def __init__(self, *args):
312312
f"not {type(path).__name__!r}")
313313
self._raw_path = path
314314

315-
def with_segments(self, *pathsegments):
315+
def with_path(self, *pathsegments):
316316
"""Construct a new path object from any number of path-like objects.
317317
Subclasses may override this method to customize how new path objects
318318
are created from methods like `iterdir()`.
@@ -342,7 +342,7 @@ def _load_parts(self):
342342

343343
def _from_parsed_parts(self, drv, root, tail):
344344
path_str = self._format_parsed_parts(drv, root, tail)
345-
path = self.with_segments(path_str)
345+
path = self.with_path(path_str)
346346
path._str = path_str or '.'
347347
path._drv = drv
348348
path._root = root
@@ -581,7 +581,7 @@ def relative_to(self, other, /, *_deprecated, walk_up=False):
581581
"scheduled for removal in Python {remove}")
582582
warnings._deprecated("pathlib.PurePath.relative_to(*args)", msg,
583583
remove=(3, 14))
584-
other = self.with_segments(other, *_deprecated)
584+
other = self.with_path(other, *_deprecated)
585585
for step, path in enumerate([other] + list(other.parents)):
586586
if self.is_relative_to(path):
587587
break
@@ -590,7 +590,7 @@ def relative_to(self, other, /, *_deprecated, walk_up=False):
590590
if step and not walk_up:
591591
raise ValueError(f"{str(self)!r} is not in the subpath of {str(other)!r}")
592592
parts = ['..'] * step + self._tail[len(path._tail):]
593-
return self.with_segments(*parts)
593+
return self.with_path(*parts)
594594

595595
def is_relative_to(self, other, /, *_deprecated):
596596
"""Return True if the path is relative to another path or False.
@@ -601,7 +601,7 @@ def is_relative_to(self, other, /, *_deprecated):
601601
"scheduled for removal in Python {remove}")
602602
warnings._deprecated("pathlib.PurePath.is_relative_to(*args)",
603603
msg, remove=(3, 14))
604-
other = self.with_segments(other, *_deprecated)
604+
other = self.with_path(other, *_deprecated)
605605
return other == self or other in self.parents
606606

607607
@property
@@ -619,7 +619,7 @@ def joinpath(self, *pathsegments):
619619
paths) or a totally different path (if one of the arguments is
620620
anchored).
621621
"""
622-
return self.with_segments(self._raw_path, *pathsegments)
622+
return self.with_path(self._raw_path, *pathsegments)
623623

624624
def __truediv__(self, key):
625625
try:
@@ -629,7 +629,7 @@ def __truediv__(self, key):
629629

630630
def __rtruediv__(self, key):
631631
try:
632-
return self.with_segments(key, self._raw_path)
632+
return self.with_path(key, self._raw_path)
633633
except TypeError:
634634
return NotImplemented
635635

@@ -678,7 +678,7 @@ def match(self, path_pattern):
678678
"""
679679
Return True if this path matches the given pattern.
680680
"""
681-
pat = self.with_segments(path_pattern)
681+
pat = self.with_path(path_pattern)
682682
if not pat.parts:
683683
raise ValueError("empty pattern")
684684
pat_parts = pat._parts_normcase
@@ -753,7 +753,7 @@ def _make_child_relpath(self, name):
753753
path_str = f'{path_str}{name}'
754754
else:
755755
path_str = name
756-
path = self.with_segments(path_str)
756+
path = self.with_path(path_str)
757757
path._str = path_str
758758
path._drv = self.drive
759759
path._root = self.root
@@ -803,7 +803,7 @@ def samefile(self, other_path):
803803
try:
804804
other_st = other_path.stat()
805805
except AttributeError:
806-
other_st = self.with_segments(other_path).stat()
806+
other_st = self.with_path(other_path).stat()
807807
return self._flavour.samestat(st, other_st)
808808

809809
def iterdir(self):
@@ -865,7 +865,7 @@ def absolute(self):
865865
cwd = self._flavour.abspath(self.drive)
866866
else:
867867
cwd = os.getcwd()
868-
return self.with_segments(cwd, self._raw_path)
868+
return self.with_path(cwd, self._raw_path)
869869

870870
def resolve(self, strict=False):
871871
"""
@@ -883,7 +883,7 @@ def check_eloop(e):
883883
except OSError as e:
884884
check_eloop(e)
885885
raise
886-
p = self.with_segments(s)
886+
p = self.with_path(s)
887887

888888
# In non-strict mode, realpath() doesn't raise on symlink loops.
889889
# Ensure we get an exception by calling stat()
@@ -973,7 +973,7 @@ def readlink(self):
973973
"""
974974
if not hasattr(os, "readlink"):
975975
raise NotImplementedError("os.readlink() not available on this system")
976-
return self.with_segments(os.readlink(self))
976+
return self.with_path(os.readlink(self))
977977

978978
def touch(self, mode=0o666, exist_ok=True):
979979
"""
@@ -1062,7 +1062,7 @@ def rename(self, target):
10621062
Returns the new Path instance pointing to the target path.
10631063
"""
10641064
os.rename(self, target)
1065-
return self.with_segments(target)
1065+
return self.with_path(target)
10661066

10671067
def replace(self, target):
10681068
"""
@@ -1075,7 +1075,7 @@ def replace(self, target):
10751075
Returns the new Path instance pointing to the target path.
10761076
"""
10771077
os.replace(self, target)
1078-
return self.with_segments(target)
1078+
return self.with_path(target)
10791079

10801080
def symlink_to(self, target, target_is_directory=False):
10811081
"""

Lib/test/test_pathlib.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def __init__(self, *args, session_id):
3333
super().__init__(*args)
3434
self.session_id = session_id
3535

36-
def with_segments(self, *args):
36+
def with_path(self, *args):
3737
return type(self)(*args, session_id=self.session_id)
3838

3939

@@ -122,7 +122,7 @@ def test_str_subclass_common(self):
122122
self._check_str_subclass('a/b.txt')
123123
self._check_str_subclass('/a/b.txt')
124124

125-
def test_with_segments_common(self):
125+
def test_with_path_common(self):
126126
class P(_BasePurePathSubclass, self.cls):
127127
pass
128128
p = P('foo', 'bar', session_id=42)
@@ -132,7 +132,7 @@ class P(_BasePurePathSubclass, self.cls):
132132
self.assertEqual(42, p.with_name('foo').session_id)
133133
self.assertEqual(42, p.with_stem('foo').session_id)
134134
self.assertEqual(42, p.with_suffix('.foo').session_id)
135-
self.assertEqual(42, p.with_segments('foo').session_id)
135+
self.assertEqual(42, p.with_path('foo').session_id)
136136
self.assertEqual(42, p.relative_to('foo').session_id)
137137
self.assertEqual(42, p.parent.session_id)
138138
for parent in p.parents:
@@ -1625,13 +1625,13 @@ def test_home(self):
16251625
env['HOME'] = os.path.join(BASE, 'home')
16261626
self._test_home(self.cls.home())
16271627

1628-
def test_with_segments(self):
1628+
def test_with_path(self):
16291629
class P(_BasePurePathSubclass, self.cls):
16301630
pass
16311631
p = P(BASE, session_id=42)
16321632
self.assertEqual(42, p.absolute().session_id)
16331633
self.assertEqual(42, p.resolve().session_id)
1634-
self.assertEqual(42, p.with_segments('~').expanduser().session_id)
1634+
self.assertEqual(42, p.with_path('~').expanduser().session_id)
16351635
self.assertEqual(42, (p / 'fileA').rename(p / 'fileB').session_id)
16361636
self.assertEqual(42, (p / 'fileB').replace(p / 'fileA').session_id)
16371637
if os_helper.can_symlink():
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Add :meth:`pathlib.PurePath.with_segments`, which creates a path object from
1+
Add :meth:`pathlib.PurePath.with_path`, which creates a path object from
22
arguments. This method is called whenever a derivative path is created, such
33
as from :attr:`pathlib.PurePath.parent`. Subclasses may override this method
44
to share information between path objects.

0 commit comments

Comments
 (0)