From 18da5e2607399d6beaa23834e94f52f26f7bc937 Mon Sep 17 00:00:00 2001 From: Elephant Liu Date: Wed, 8 Jan 2020 21:30:56 +0800 Subject: [PATCH] keep traceback when reject promise list --- promise/promise_list.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/promise/promise_list.py b/promise/promise_list.py index 071c77f..de142f9 100644 --- a/promise/promise_list.py +++ b/promise/promise_list.py @@ -1,4 +1,5 @@ from functools import partial +from types import TracebackType try: from collections.abc import Iterable except ImportError: @@ -90,14 +91,14 @@ def _iterate(self, values): if maybe_promise.is_pending: maybe_promise._add_callbacks( partial(self._promise_fulfilled, i=i), - self._promise_rejected, + partial(self._promise_rejected, promise=maybe_promise), None, ) self._values[i] = maybe_promise elif maybe_promise.is_fulfilled: is_resolved = self._promise_fulfilled(maybe_promise._value(), i) elif maybe_promise.is_rejected: - is_resolved = self._promise_rejected(maybe_promise._reason()) + is_resolved = self._promise_rejected(maybe_promise._reason(), promise=maybe_promise) else: is_resolved = self._promise_fulfilled(val, i) @@ -122,14 +123,14 @@ def _promise_fulfilled(self, value, i): return True return False - def _promise_rejected(self, reason): - # type: (Exception) -> bool + def _promise_rejected(self, reason, promise): + # type: (Exception, Promise) -> bool if self.is_resolved: return False # assert not self.is_resolved # assert isinstance(self._values, Iterable) self._total_resolved += 1 - self._reject(reason) + self._reject(reason, traceback=promise._traceback) return True @property @@ -144,8 +145,8 @@ def _resolve(self, value): self._values = None self.promise._fulfill(value) - def _reject(self, reason): - # type: (Exception) -> None + def _reject(self, reason, traceback=None): + # type: (Exception, Optional[TracebackType]) -> None assert not self.is_resolved self._values = None - self.promise._reject_callback(reason, False) + self.promise._reject_callback(reason, False, traceback=traceback)