Skip to content

Commit 05ea420

Browse files
committed
upath: fixes for extensions, StatResultType
1 parent 7073918 commit 05ea420

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

upath/extensions.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,9 @@ def is_absolute(self) -> bool:
284284
return self.__wrapped__.is_absolute()
285285

286286
def __eq__(self, other: object) -> bool:
287-
return self.__wrapped__.__eq__(other)
287+
if not isinstance(other, type(self)):
288+
return NotImplemented
289+
return self.__wrapped__.__eq__(other.__wrapped__)
288290

289291
def __hash__(self) -> int:
290292
return self.__wrapped__.__hash__()
@@ -313,8 +315,11 @@ def lchmod(self, mode: int) -> None:
313315
def unlink(self, missing_ok: bool = False) -> None:
314316
self.__wrapped__.unlink(missing_ok=missing_ok)
315317

316-
def rmdir(self, recursive: bool = True) -> None: # fixme: non-standard
317-
self.__wrapped__.rmdir(recursive=recursive)
318+
def rmdir(self, recursive: bool = UNSET_DEFAULT) -> None: # fixme: non-standard
319+
kwargs: dict[str, Any] = {}
320+
if recursive is not UNSET_DEFAULT:
321+
kwargs["recursive"] = recursive
322+
self.__wrapped__.rmdir(**kwargs)
318323

319324
def rename(
320325
self,
@@ -324,9 +329,14 @@ def rename(
324329
maxdepth: int | None = UNSET_DEFAULT,
325330
**kwargs: Any,
326331
) -> Self:
332+
if recursive is not UNSET_DEFAULT:
333+
kwargs["recursive"] = recursive
334+
if maxdepth is not UNSET_DEFAULT:
335+
kwargs["maxdepth"] = maxdepth
327336
return self._from_upath(
328337
self.__wrapped__.rename(
329-
target, recursive=recursive, maxdepth=maxdepth, **kwargs
338+
target.__wrapped__ if isinstance(target, ProxyUPath) else target,
339+
**kwargs,
330340
)
331341
)
332342

upath/implementations/local.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import os
44
import pathlib
5+
import shutil
56
import sys
67
import warnings
78
from collections.abc import Iterator
@@ -316,6 +317,12 @@ def open(
316317
**fsspec_kwargs,
317318
)
318319

320+
def rmdir(self, recursive: bool = UNSET_DEFAULT) -> None:
321+
if recursive is UNSET_DEFAULT or not recursive:
322+
return super().rmdir()
323+
else:
324+
shutil.rmtree(self)
325+
319326
if sys.version_info < (3, 14): # noqa: C901
320327

321328
@overload

upath/types/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ class _DefaultValue(enum.Enum):
6161
# WritablePath.register(pathlib.Path)
6262

6363

64+
@runtime_checkable
6465
class StatResultType(Protocol):
6566
"""duck-type for os.stat_result"""
6667

0 commit comments

Comments
 (0)