summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Lib/pathlib.py3
-rw-r--r--Misc/NEWS.d/next/Library/2023-11-25-20-29-28.gh-issue-112405.cOtzxC.rst1
2 files changed, 3 insertions, 1 deletions
diff --git a/Lib/pathlib.py b/Lib/pathlib.py
index 0e01099..81f75cd 100644
--- a/Lib/pathlib.py
+++ b/Lib/pathlib.py
@@ -14,6 +14,7 @@ import sys
import warnings
from _collections_abc import Sequence
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
try:
@@ -445,7 +446,7 @@ class PurePath:
other = self.with_segments(other, *_deprecated)
elif not isinstance(other, PurePath):
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:
break
elif not walk_up:
diff --git a/Misc/NEWS.d/next/Library/2023-11-25-20-29-28.gh-issue-112405.cOtzxC.rst b/Misc/NEWS.d/next/Library/2023-11-25-20-29-28.gh-issue-112405.cOtzxC.rst
new file mode 100644
index 0000000..f6f1bee
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2023-11-25-20-29-28.gh-issue-112405.cOtzxC.rst
@@ -0,0 +1 @@
+Optimize :meth:`pathlib.PurePath.relative_to`. Patch by Alex Waygood.