Deprecate scrapy.utils.py36 module

This commit is contained in:
Eugenio Lacuesta 2020-11-23 11:59:59 -03:00
parent e17c890be1
commit 075ab156b0
No known key found for this signature in database
GPG Key ID: DA3EF2D0913E9810
4 changed files with 18 additions and 16 deletions

View File

@ -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,
)

View File

@ -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

View File

@ -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

View File

@ -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