Skip to content

Commit

Permalink
Fixed py3.10 compatibility for _parts in pathlike (#135)
Browse files Browse the repository at this point in the history
  • Loading branch information
nfx authored Jul 16, 2024
1 parent 49c74a3 commit 821bc0a
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/databricks/labs/blueprint/paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,14 +292,13 @@ def __hash__(self) -> int:
self._hash = hash(str(self))
return self._hash

@property
def _parts(self) -> tuple[str, ...]:
"""Return a tuple that has the same natural ordering as paths of this type."""
# Compatibility property (python <= 3.11), accessed via reverse equality comparison. This can't be avoided.
return self._root, *self._path_parts

@property
def _cparts(self):
# Compatibility property (python <= 3.11), accessed via reverse equality comparison. This can't be avoided.
return self._parts()
_cparts = _parts

@property
def _str_normcase(self):
Expand Down Expand Up @@ -443,7 +442,7 @@ def joinpath(self: P, *path_segments) -> P:

def __truediv__(self: P, other: str | bytes | os.PathLike) -> P:
try:
return self.with_segments(*self._parts(), other)
return self.with_segments(*self._parts, other)
except TypeError:
return NotImplemented

Expand All @@ -455,8 +454,8 @@ def __rtruediv__(self, other):
# control ends up here.
try:
if isinstance(other, PurePath):
return type(other)(other, *self._parts())
return self.with_segments(other, *self._parts())
return type(other)(other, *self._parts)
return self.with_segments(other, *self._parts)
except TypeError:
return NotImplemented

Expand Down

0 comments on commit 821bc0a

Please sign in to comment.