Skip to content

Commit

Permalink
try to avoid some calculations
Browse files Browse the repository at this point in the history
  • Loading branch information
bdraco committed Oct 22, 2024
1 parent 4dc41af commit a020004
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions yarl/_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from collections.abc import Sequence
from contextlib import suppress
from itertools import chain
from pathlib import PurePosixPath


Expand Down Expand Up @@ -57,9 +58,8 @@ def calculate_relative_path(target: str, base: str) -> str:
if base[-1] != "/":
base_path = base_path.parent

target_paths = {target_path, *target_path.parents}
for step, path in enumerate((base_path, *base_path.parents)):
if path in target_paths:
for step, path in enumerate(chain((base_path,), base_path.parents)):
if path == target_path or path in target_path.parents:
break
elif path.name == "..":
raise ValueError(f"'..' segment in {str(base_path)!r} cannot be walked")
Expand Down

0 comments on commit a020004

Please sign in to comment.