@@ -647,9 +647,11 @@ def relative_to(self, other, /, *_deprecated, walk_up=False):
647
647
"scheduled for removal in Python {remove}" )
648
648
warnings ._deprecated ("pathlib.PurePath.relative_to(*args)" , msg ,
649
649
remove = (3 , 14 ))
650
- other = self .with_segments (other , * _deprecated )
650
+ other = self .with_segments (other , * _deprecated )
651
+ elif not isinstance (other , PurePath ):
652
+ other = self .with_segments (other )
651
653
for step , path in enumerate ([other ] + list (other .parents )):
652
- if self . is_relative_to ( path ) :
654
+ if path == self or path in self . parents :
653
655
break
654
656
elif not walk_up :
655
657
raise ValueError (f"{ str (self )!r} is not in the subpath of { str (other )!r} " )
@@ -658,7 +660,7 @@ def relative_to(self, other, /, *_deprecated, walk_up=False):
658
660
else :
659
661
raise ValueError (f"{ str (self )!r} and { str (other )!r} have different anchors" )
660
662
parts = ['..' ] * step + self ._tail [len (path ._tail ):]
661
- return self .with_segments ( * parts )
663
+ return self ._from_parsed_parts ( '' , '' , parts )
662
664
663
665
def is_relative_to (self , other , / , * _deprecated ):
664
666
"""Return True if the path is relative to another path or False.
@@ -669,7 +671,9 @@ def is_relative_to(self, other, /, *_deprecated):
669
671
"scheduled for removal in Python {remove}" )
670
672
warnings ._deprecated ("pathlib.PurePath.is_relative_to(*args)" ,
671
673
msg , remove = (3 , 14 ))
672
- other = self .with_segments (other , * _deprecated )
674
+ other = self .with_segments (other , * _deprecated )
675
+ elif not isinstance (other , PurePath ):
676
+ other = self .with_segments (other )
673
677
return other == self or other in self .parents
674
678
675
679
@property
0 commit comments