Skip to content

Commit befbf1a

Browse files
committed
With py39 dropped, revert 44d628d as not needed anymore
Otherwise, we run into backwards incompatible change in py314, partial being a method descriptor, hence requiring a staticmethod wrapper here. See python/cpython#121027.
1 parent edb0985 commit befbf1a

3 files changed

Lines changed: 18 additions & 16 deletions

File tree

‎dwave/cloud/api/client.py‎

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -355,19 +355,6 @@ def request(self, *args, headers: Optional[dict] = None, **kwargs) -> requests.R
355355
return response
356356

357357

358-
def _create_default_cache_store(**kwargs) -> abc.Mapping:
359-
# TODO: de-dup vs `dwave.cloud.utils.decorators.cached`?
360-
361-
# defer to break circular imports
362-
from dwave.cloud.config import get_cache_dir
363-
364-
directory = kwargs.pop('directory', os.path.join(get_cache_dir(), 'api'))
365-
366-
# defer import and construction until needed
367-
import diskcache
368-
return diskcache.Cache(directory=directory)
369-
370-
371358
class VersionedAPISession(VersionedAPISessionMixin, PayloadCompressingSession):
372359
pass
373360

@@ -406,6 +393,19 @@ class CachingSessionMixin:
406393
Force cache update, skipping time-based or etag-based validation.
407394
"""
408395

396+
@staticmethod
397+
def _create_default_cache_store(**kwargs) -> abc.Mapping:
398+
# TODO: de-dup vs `dwave.cloud.utils.decorators.cached`?
399+
400+
# defer to break circular imports
401+
from dwave.cloud.config import get_cache_dir
402+
403+
directory = kwargs.pop('directory', os.path.join(get_cache_dir(), 'api'))
404+
405+
# defer import and construction until needed
406+
import diskcache
407+
return diskcache.Cache(directory=directory)
408+
409409
class CacheConfig(TypedDict, total=False):
410410
enabled: bool
411411
maxage: float

‎tests/api/resources/test_solvers.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ class TestLiveSolversCaching(unittest.TestCase):
267267
@classmethod
268268
def setUpClass(cls):
269269
cls.tmpdir = tempfile.TemporaryDirectory()
270-
cls.store = partial(CachingSessionMixin._default_cache_config['store'],
270+
cls.store = partial(CachingSessionMixin._create_default_cache_store,
271271
directory=cls.tmpdir.name)
272272
cls.filter_ids = 'none,+identity'
273273

‎tests/test_cli.py‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
from dwave.cloud.config.models import validate_config_v1
3131
from dwave.cloud.testing import isolated_environ
3232
from dwave.cloud.auth.creds import Credentials, CREDS_FILENAME
33-
from dwave.cloud.api.client import _create_default_cache_store
33+
from dwave.cloud.api.client import CachingSessionMixin
3434
from dwave.cloud.api.models import LeapProject
3535
from dwave.cloud.api.resources import Regions
3636

@@ -730,7 +730,9 @@ def test_api_cache(self):
730730
self.assertIn("Cache empty.", result.output)
731731

732732
# populate api cache
733-
store = partial(_create_default_cache_store, directory=str(self.tmpdir / 'api'))
733+
store = staticmethod(partial(
734+
CachingSessionMixin._create_default_cache_store,
735+
directory=str(self.tmpdir / 'api')))
734736
with Regions(cache=dict(store=store)) as regions:
735737
regions.list_regions()
736738

0 commit comments

Comments
 (0)