From e1d8ebd439dbf9ab986da88900f1e6da7a097d82 Mon Sep 17 00:00:00 2001 From: Andreas Poehlmann Date: Sun, 28 Dec 2025 15:12:00 +0100 Subject: [PATCH] upath.implementations.cloud: fix error handling on HfPath --- upath/implementations/cloud.py | 36 ++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/upath/implementations/cloud.py b/upath/implementations/cloud.py index 3f037796..02c89db3 100644 --- a/upath/implementations/cloud.py +++ b/upath/implementations/cloud.py @@ -1,9 +1,11 @@ from __future__ import annotations import sys +from collections.abc import Iterator from typing import TYPE_CHECKING from typing import Any +from upath import UnsupportedOperation from upath._chain import DEFAULT_CHAIN_PARSER from upath._flavour import upath_strip_protocol from upath.core import UPath @@ -13,8 +15,10 @@ from typing import Literal if sys.version_info >= (3, 11): + from typing import Self from typing import Unpack else: + from typing_extensions import Self from typing_extensions import Unpack from upath._chain import FSSpecChainParser @@ -166,3 +170,35 @@ def __init__( super().__init__( *args, protocol=protocol, chain_parser=chain_parser, **storage_options ) + + def iterdir(self) -> Iterator[Self]: + try: + yield from super().iterdir() + except NotImplementedError: + raise UnsupportedOperation + + def touch(self, mode: int = 0o666, exist_ok: bool = True) -> None: + raise UnsupportedOperation + + def mkdir( + self, + mode: int = 0o777, + parents: bool = False, + exist_ok: bool = False, + ) -> None: + raise UnsupportedOperation + + def unlink(self, missing_ok: bool = False) -> None: + raise UnsupportedOperation + + def write_bytes(self, data: bytes) -> int: + raise UnsupportedOperation("DataPath does not support writing") + + def write_text( + self, + data: str, + encoding: str | None = None, + errors: str | None = None, + newline: str | None = None, + ) -> int: + raise UnsupportedOperation("DataPath does not support writing")