mirror of
https://github.com/python/cpython.git
synced 2025-08-01 07:33:08 +00:00
gh-112405: Optimise pathlib.Path.relative_to
(#112406)
This commit is contained in:
parent
9fe60340d7
commit
418d585feb
2 changed files with 3 additions and 1 deletions
|
@ -14,6 +14,7 @@ import sys
|
||||||
import warnings
|
import warnings
|
||||||
from _collections_abc import Sequence
|
from _collections_abc import Sequence
|
||||||
from errno import ENOENT, ENOTDIR, EBADF, ELOOP, EINVAL
|
from errno import ENOENT, ENOTDIR, EBADF, ELOOP, EINVAL
|
||||||
|
from itertools import chain
|
||||||
from stat import S_ISDIR, S_ISLNK, S_ISREG, S_ISSOCK, S_ISBLK, S_ISCHR, S_ISFIFO
|
from stat import S_ISDIR, S_ISLNK, S_ISREG, S_ISSOCK, S_ISBLK, S_ISCHR, S_ISFIFO
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -445,7 +446,7 @@ class PurePath:
|
||||||
other = self.with_segments(other, *_deprecated)
|
other = self.with_segments(other, *_deprecated)
|
||||||
elif not isinstance(other, PurePath):
|
elif not isinstance(other, PurePath):
|
||||||
other = self.with_segments(other)
|
other = self.with_segments(other)
|
||||||
for step, path in enumerate([other] + list(other.parents)):
|
for step, path in enumerate(chain([other], other.parents)):
|
||||||
if path == self or path in self.parents:
|
if path == self or path in self.parents:
|
||||||
break
|
break
|
||||||
elif not walk_up:
|
elif not walk_up:
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Optimize :meth:`pathlib.PurePath.relative_to`. Patch by Alex Waygood.
|
Loading…
Add table
Add a link
Reference in a new issue