Skip to content

Commit ef8888a

Browse files
authored
upath.implementations.cloud: fix error handling on HfPath (#521)
1 parent 043248d commit ef8888a

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

upath/implementations/cloud.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
from __future__ import annotations
22

33
import sys
4+
from collections.abc import Iterator
45
from typing import TYPE_CHECKING
56
from typing import Any
67

8+
from upath import UnsupportedOperation
79
from upath._chain import DEFAULT_CHAIN_PARSER
810
from upath._flavour import upath_strip_protocol
911
from upath.core import UPath
@@ -13,8 +15,10 @@
1315
from typing import Literal
1416

1517
if sys.version_info >= (3, 11):
18+
from typing import Self
1619
from typing import Unpack
1720
else:
21+
from typing_extensions import Self
1822
from typing_extensions import Unpack
1923

2024
from upath._chain import FSSpecChainParser
@@ -166,3 +170,35 @@ def __init__(
166170
super().__init__(
167171
*args, protocol=protocol, chain_parser=chain_parser, **storage_options
168172
)
173+
174+
def iterdir(self) -> Iterator[Self]:
175+
try:
176+
yield from super().iterdir()
177+
except NotImplementedError:
178+
raise UnsupportedOperation
179+
180+
def touch(self, mode: int = 0o666, exist_ok: bool = True) -> None:
181+
raise UnsupportedOperation
182+
183+
def mkdir(
184+
self,
185+
mode: int = 0o777,
186+
parents: bool = False,
187+
exist_ok: bool = False,
188+
) -> None:
189+
raise UnsupportedOperation
190+
191+
def unlink(self, missing_ok: bool = False) -> None:
192+
raise UnsupportedOperation
193+
194+
def write_bytes(self, data: bytes) -> int:
195+
raise UnsupportedOperation("DataPath does not support writing")
196+
197+
def write_text(
198+
self,
199+
data: str,
200+
encoding: str | None = None,
201+
errors: str | None = None,
202+
newline: str | None = None,
203+
) -> int:
204+
raise UnsupportedOperation("DataPath does not support writing")

0 commit comments

Comments
 (0)