From c088f7c1380139206fbbc21e355a0e2dfc2d9207 Mon Sep 17 00:00:00 2001 From: Elvis Pranskevichus Date: Thu, 1 Nov 2018 19:43:12 -0400 Subject: [PATCH 1/3] Fix Python 3.7 deprecation warnings Importing ABCs directly from the `collections` module is deprecated in Python 3.7. --- promise/dataloader.py | 6 +++++- promise/promise_list.py | 5 ++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/promise/dataloader.py b/promise/dataloader.py index e2c9e43..1c4e4ef 100644 --- a/promise/dataloader.py +++ b/promise/dataloader.py @@ -1,4 +1,8 @@ -from collections import Iterable, namedtuple +from collections import namedtuple +try: + from collections.abc import Iterable +except ImportError: + from collections import Iterable from functools import partial from .promise import Promise, async_instance, get_default_scheduler diff --git a/promise/promise_list.py b/promise/promise_list.py index 0112d7d..071c77f 100644 --- a/promise/promise_list.py +++ b/promise/promise_list.py @@ -1,5 +1,8 @@ from functools import partial -from collections import Iterable +try: + from collections.abc import Iterable +except ImportError: + from collections import Iterable if False: from .promise import Promise From 4861d8172a088131466aad7aeb8178ace95a9143 Mon Sep 17 00:00:00 2001 From: Don Brown Date: Wed, 4 Dec 2019 14:36:40 -0700 Subject: [PATCH 2/3] Fix deprecation warnings --- promise/dataloader.py | 6 +----- promise/promise.py | 4 ++-- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/promise/dataloader.py b/promise/dataloader.py index 1c4e4ef..f4dc4a8 100644 --- a/promise/dataloader.py +++ b/promise/dataloader.py @@ -71,16 +71,12 @@ def __init__( if cache is not None: self.cache = cache - if get_cache_key is not None: - self.get_cache_key = get_cache_key + self.get_cache_key = get_cache_key or (lambda x: x) self._promise_cache = cache_map or {} self._queue = [] # type: List[Loader] self._scheduler = scheduler - def get_cache_key(self, key): # type: ignore - return key - def load(self, key=None): # type: (Hashable) -> Promise """ diff --git a/promise/promise.py b/promise/promise.py index 1c2f1c0..7169a84 100644 --- a/promise/promise.py +++ b/promise/promise.py @@ -319,7 +319,7 @@ def _settle_promise( if async_guaranteed: promise._is_async_guaranteed = True # type: ignore self._settle_promise_from_handler( # type: ignore - handler, value, promise + handler, value, promise # type: ignore ) # type: ignore elif is_promise: if async_guaranteed: @@ -567,7 +567,7 @@ def _then( did_reject=None, # type: Optional[Callable[[Exception], S]] ): # type: (...) -> Promise[S] - promise = self.__class__() + promise = self.__class__() # type: Promise target = self._target() state = target._state From 03bd9902d9a583f42ec7d4e41d346bed60867ba2 Mon Sep 17 00:00:00 2001 From: Don Brown Date: Wed, 4 Dec 2019 14:45:44 -0700 Subject: [PATCH 3/3] Fix another mypy issue --- promise/promise.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/promise/promise.py b/promise/promise.py index 7169a84..611a83d 100644 --- a/promise/promise.py +++ b/promise/promise.py @@ -791,7 +791,7 @@ def for_dict(cls, m): dict_type = type(m) # type: Type[Dict] if not m: - return cls.resolve(dict_type()) + return cls.resolve(dict_type()) # type: ignore def handle_success(resolved_values): # type: (List[S]) -> Dict[Hashable, S]