Skip to content

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

Deprecate scrapy.utils.py36 module

Eugenio Lacuesta075ab156b0ac
diff --git a/scrapy/utils/py36.py b/scrapy/utils/py36.py
index c8c24076e..070b145a4 100644
--- a/scrapy/utils/py36.py
+++ b/scrapy/utils/py36.py
@@ -1,10 +1,11 @@
-"""
-Helpers using Python 3.6+ syntax (ignore SyntaxError on import).
-"""
+import warnings
+from scrapy.exceptions import ScrapyDeprecationWarning
+from scrapy.utils.python import collect_asyncgen # noqa: F401
-async def collect_asyncgen(result):
- results = []
- async for x in result:
- results.append(x)
- return results
+
+warnings.warn(
+ "Module `scrapy.utils.py36` is deprecated, please import from `scrapy.utils.python` instead.",
+ category=ScrapyDeprecationWarning,
+ stacklevel=2,
+)
diff --git a/scrapy/utils/python.py b/scrapy/utils/python.py
index 5703fd4c3..7bd286523 100644
--- a/scrapy/utils/python.py
+++ b/scrapy/utils/python.py
@@ -355,3 +355,10 @@ class MutableChain:
@deprecated("scrapy.utils.python.MutableChain.__next__")
def next(self):
return self.__next__()
+
+
+async def collect_asyncgen(result):
+ results = []
+ async for x in result:
+ results.append(x)
+ return results
diff --git a/scrapy/utils/spider.py b/scrapy/utils/spider.py
index f3a9a67a3..5319604ba 100644
--- a/scrapy/utils/spider.py
+++ b/scrapy/utils/spider.py
@@ -4,17 +4,14 @@ import logging
from scrapy.spiders import Spider
from scrapy.utils.defer import deferred_from_coro
from scrapy.utils.misc import arg_to_iter
-try:
- from scrapy.utils.py36 import collect_asyncgen
-except SyntaxError:
- collect_asyncgen = None
+from scrapy.utils.python import collect_asyncgen
logger = logging.getLogger(__name__)
def iterate_spider_output(result):
- if collect_asyncgen and hasattr(inspect, 'isasyncgen') and inspect.isasyncgen(result):
+ if inspect.isasyncgen(result):
d = deferred_from_coro(collect_asyncgen(result))
d.addCallback(iterate_spider_output)
return d
diff --git a/setup.cfg b/setup.cfg
index 8101443e3..0c9f6b963 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -55,9 +55,6 @@ ignore_errors = True
[mypy-scrapy.utils.response]
ignore_errors = True
-[mypy-scrapy.utils.spider]
-ignore_errors = True
-
[mypy-scrapy.utils.trackref]
ignore_errors = True