Skip to content

Commit fb38a2d

Browse files
committed
make HTTPClient.cache compulsory
1 parent 001caad commit fb38a2d

2 files changed

Lines changed: 3 additions & 24 deletions

File tree

openml/_api/clients/http.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
from openml.__version__ import __version__
2020
from openml.enums import RetryPolicy
2121
from openml.exceptions import (
22-
OpenMLCacheRequiredError,
2322
OpenMLHashException,
2423
OpenMLNotAuthorizedError,
2524
OpenMLServerError,
@@ -231,7 +230,7 @@ def __init__( # noqa: PLR0913
231230
api_key: str,
232231
retries: int,
233232
retry_policy: RetryPolicy,
234-
cache: HTTPCache | None = None,
233+
cache: HTTPCache,
235234
) -> None:
236235
self.server = server
237236
self.base_url = base_url
@@ -608,7 +607,7 @@ def request( # noqa: PLR0913, C901
608607

609608
files = request_kwargs.pop("files", None)
610609

611-
if use_cache and not reset_cache and self.cache is not None:
610+
if use_cache and not reset_cache:
612611
cache_key = self.cache.get_key(url, params)
613612
try:
614613
return self.cache.load(cache_key)
@@ -647,7 +646,7 @@ def request( # noqa: PLR0913, C901
647646
if md5_checksum is not None:
648647
self._verify_checksum(response, md5_checksum)
649648

650-
if use_cache and self.cache is not None:
649+
if use_cache:
651650
cache_key = self.cache.get_key(url, params)
652651
self.cache.save(cache_key, response)
653652

@@ -812,15 +811,9 @@ def download(
812811
813812
Raises
814813
------
815-
OpenMLCacheRequiredError
816-
If no cache instance is configured.
817814
OpenMLHashException
818815
If checksum verification fails.
819816
"""
820-
if self.cache is None:
821-
raise OpenMLCacheRequiredError(
822-
"A cache object is required for download, but none was provided in the HTTPClient."
823-
)
824817
base = self.cache.path
825818
file_path = base / "downloads" / urlparse(url).path.lstrip("/") / file_name
826819
file_path = file_path.expanduser()

tests/test_api/test_http.py

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
from urllib.parse import urljoin
99
from openml.enums import APIVersion
1010
from openml._api import HTTPClient
11-
from openml.exceptions import OpenMLCacheRequiredError
1211

1312

1413
class TestHTTPClient(TestAPIBase):
@@ -149,19 +148,6 @@ def test_post_and_delete(self):
149148
response = self.http_client.delete(f"task/{task_id}")
150149
self.assertEqual(response.status_code, 200)
151150

152-
def test_download_requires_cache(self):
153-
client = HTTPClient(
154-
server=self.http_client.server,
155-
base_url=self.http_client.base_url,
156-
api_key=self.http_client.api_key,
157-
retries=1,
158-
retry_policy=self.http_client.retry_policy,
159-
cache=None,
160-
)
161-
162-
with pytest.raises(OpenMLCacheRequiredError):
163-
client.download("https://www.openml.org")
164-
165151
@pytest.mark.uses_test_server()
166152
def test_download_creates_file(self):
167153
# small stable resource

0 commit comments

Comments
 (0)