@@ -312,7 +312,7 @@ def __init__(self, *args):
312
312
f"not { type (path ).__name__ !r} " )
313
313
self ._raw_path = path
314
314
315
- def with_segments (self , * pathsegments ):
315
+ def with_path (self , * pathsegments ):
316
316
"""Construct a new path object from any number of path-like objects.
317
317
Subclasses may override this method to customize how new path objects
318
318
are created from methods like `iterdir()`.
@@ -342,7 +342,7 @@ def _load_parts(self):
342
342
343
343
def _from_parsed_parts (self , drv , root , tail ):
344
344
path_str = self ._format_parsed_parts (drv , root , tail )
345
- path = self .with_segments (path_str )
345
+ path = self .with_path (path_str )
346
346
path ._str = path_str or '.'
347
347
path ._drv = drv
348
348
path ._root = root
@@ -581,7 +581,7 @@ def relative_to(self, other, /, *_deprecated, walk_up=False):
581
581
"scheduled for removal in Python {remove}" )
582
582
warnings ._deprecated ("pathlib.PurePath.relative_to(*args)" , msg ,
583
583
remove = (3 , 14 ))
584
- other = self .with_segments (other , * _deprecated )
584
+ other = self .with_path (other , * _deprecated )
585
585
for step , path in enumerate ([other ] + list (other .parents )):
586
586
if self .is_relative_to (path ):
587
587
break
@@ -590,7 +590,7 @@ def relative_to(self, other, /, *_deprecated, walk_up=False):
590
590
if step and not walk_up :
591
591
raise ValueError (f"{ str (self )!r} is not in the subpath of { str (other )!r} " )
592
592
parts = ['..' ] * step + self ._tail [len (path ._tail ):]
593
- return self .with_segments (* parts )
593
+ return self .with_path (* parts )
594
594
595
595
def is_relative_to (self , other , / , * _deprecated ):
596
596
"""Return True if the path is relative to another path or False.
@@ -601,7 +601,7 @@ def is_relative_to(self, other, /, *_deprecated):
601
601
"scheduled for removal in Python {remove}" )
602
602
warnings ._deprecated ("pathlib.PurePath.is_relative_to(*args)" ,
603
603
msg , remove = (3 , 14 ))
604
- other = self .with_segments (other , * _deprecated )
604
+ other = self .with_path (other , * _deprecated )
605
605
return other == self or other in self .parents
606
606
607
607
@property
@@ -619,7 +619,7 @@ def joinpath(self, *pathsegments):
619
619
paths) or a totally different path (if one of the arguments is
620
620
anchored).
621
621
"""
622
- return self .with_segments (self ._raw_path , * pathsegments )
622
+ return self .with_path (self ._raw_path , * pathsegments )
623
623
624
624
def __truediv__ (self , key ):
625
625
try :
@@ -629,7 +629,7 @@ def __truediv__(self, key):
629
629
630
630
def __rtruediv__ (self , key ):
631
631
try :
632
- return self .with_segments (key , self ._raw_path )
632
+ return self .with_path (key , self ._raw_path )
633
633
except TypeError :
634
634
return NotImplemented
635
635
@@ -678,7 +678,7 @@ def match(self, path_pattern):
678
678
"""
679
679
Return True if this path matches the given pattern.
680
680
"""
681
- pat = self .with_segments (path_pattern )
681
+ pat = self .with_path (path_pattern )
682
682
if not pat .parts :
683
683
raise ValueError ("empty pattern" )
684
684
pat_parts = pat ._parts_normcase
@@ -753,7 +753,7 @@ def _make_child_relpath(self, name):
753
753
path_str = f'{ path_str } { name } '
754
754
else :
755
755
path_str = name
756
- path = self .with_segments (path_str )
756
+ path = self .with_path (path_str )
757
757
path ._str = path_str
758
758
path ._drv = self .drive
759
759
path ._root = self .root
@@ -803,7 +803,7 @@ def samefile(self, other_path):
803
803
try :
804
804
other_st = other_path .stat ()
805
805
except AttributeError :
806
- other_st = self .with_segments (other_path ).stat ()
806
+ other_st = self .with_path (other_path ).stat ()
807
807
return self ._flavour .samestat (st , other_st )
808
808
809
809
def iterdir (self ):
@@ -865,7 +865,7 @@ def absolute(self):
865
865
cwd = self ._flavour .abspath (self .drive )
866
866
else :
867
867
cwd = os .getcwd ()
868
- return self .with_segments (cwd , self ._raw_path )
868
+ return self .with_path (cwd , self ._raw_path )
869
869
870
870
def resolve (self , strict = False ):
871
871
"""
@@ -883,7 +883,7 @@ def check_eloop(e):
883
883
except OSError as e :
884
884
check_eloop (e )
885
885
raise
886
- p = self .with_segments (s )
886
+ p = self .with_path (s )
887
887
888
888
# In non-strict mode, realpath() doesn't raise on symlink loops.
889
889
# Ensure we get an exception by calling stat()
@@ -973,7 +973,7 @@ def readlink(self):
973
973
"""
974
974
if not hasattr (os , "readlink" ):
975
975
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 ))
977
977
978
978
def touch (self , mode = 0o666 , exist_ok = True ):
979
979
"""
@@ -1062,7 +1062,7 @@ def rename(self, target):
1062
1062
Returns the new Path instance pointing to the target path.
1063
1063
"""
1064
1064
os .rename (self , target )
1065
- return self .with_segments (target )
1065
+ return self .with_path (target )
1066
1066
1067
1067
def replace (self , target ):
1068
1068
"""
@@ -1075,7 +1075,7 @@ def replace(self, target):
1075
1075
Returns the new Path instance pointing to the target path.
1076
1076
"""
1077
1077
os .replace (self , target )
1078
- return self .with_segments (target )
1078
+ return self .with_path (target )
1079
1079
1080
1080
def symlink_to (self , target , target_is_directory = False ):
1081
1081
"""
0 commit comments