Skip to content

Scrapy, a fast high-level web crawling & scraping framework for Python.

Deprecate scrapy.utils.defer.process_chain_both(). (#6397)

Andrey Rakhmatullinddc98fe91b45
diff --git a/scrapy/utils/defer.py b/scrapy/utils/defer.py
index abb7e1726..f60b7dde8 100644
--- a/scrapy/utils/defer.py
+++ b/scrapy/utils/defer.py
@@ -6,6 +6,7 @@ from __future__ import annotations
import asyncio
import inspect
+import warnings
from asyncio import Future
from functools import wraps
from types import CoroutineType
@@ -35,7 +36,7 @@ from twisted.internet.task import Cooperator
from twisted.python import failure
from twisted.python.failure import Failure
-from scrapy.exceptions import IgnoreRequest
+from scrapy.exceptions import IgnoreRequest, ScrapyDeprecationWarning
from scrapy.utils.reactor import _get_asyncio_event_loop, is_asyncio_reactor_installed
if TYPE_CHECKING:
@@ -281,6 +282,12 @@ def process_chain_both(
**kw: _P.kwargs,
) -> Deferred:
"""Return a Deferred built by chaining the given callbacks and errbacks"""
+ warnings.warn(
+ "process_chain_both() is deprecated and will be removed in a future"
+ " Scrapy version.",
+ ScrapyDeprecationWarning,
+ stacklevel=2,
+ )
d: Deferred = Deferred()
for cb, eb in zip(callbacks, errbacks):
d.addCallback(cb, *a, **kw)
diff --git a/tests/test_utils_defer.py b/tests/test_utils_defer.py
index a7d54b565..ec0399865 100644
--- a/tests/test_utils_defer.py
+++ b/tests/test_utils_defer.py
@@ -14,7 +14,6 @@ from scrapy.utils.defer import (
mustbe_deferred,
parallel_async,
process_chain,
- process_chain_both,
process_parallel,
)
@@ -80,19 +79,6 @@ class DeferUtilsTest(unittest.TestCase):
gotexc = True
self.assertTrue(gotexc)
- @defer.inlineCallbacks
- def test_process_chain_both(self):
- x = yield process_chain_both(
- [cb_fail, cb2, cb3], [None, eb1, None], "res", "v1", "v2"
- )
- self.assertEqual(x, "(cb3 (eb1 TypeError v1 v2) v1 v2)")
-
- fail = Failure(ZeroDivisionError())
- x = yield process_chain_both(
- [eb1, cb2, cb3], [eb1, None, None], fail, "v1", "v2"
- )
- self.assertEqual(x, "(cb3 (cb2 (eb1 ZeroDivisionError v1 v2) v1 v2) v1 v2)")
-
@defer.inlineCallbacks
def test_process_parallel(self):
x = yield process_parallel([cb1, cb2, cb3], "res", "v1", "v2")