mirror of https://github.com/scrapy/scrapy.git
Merge pull request #5599 from tonal/patch-1
Partial in is_generator_with_return_value
This commit is contained in:
commit
a95a338eea
|
|
@ -9,6 +9,7 @@ from collections import deque
|
|||
from contextlib import contextmanager
|
||||
from importlib import import_module
|
||||
from pkgutil import iter_modules
|
||||
from functools import partial
|
||||
|
||||
from w3lib.html import replace_entities
|
||||
|
||||
|
|
@ -226,7 +227,11 @@ def is_generator_with_return_value(callable):
|
|||
return value is None or isinstance(value, ast.NameConstant) and value.value is None
|
||||
|
||||
if inspect.isgeneratorfunction(callable):
|
||||
src = inspect.getsource(callable)
|
||||
func = callable
|
||||
while isinstance(func, partial):
|
||||
func = func.func
|
||||
|
||||
src = inspect.getsource(func)
|
||||
pattern = re.compile(r"(^[\t ]+)")
|
||||
code = pattern.sub("", src)
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import unittest
|
||||
import warnings
|
||||
from functools import partial
|
||||
from unittest import mock
|
||||
|
||||
from scrapy.utils.misc import is_generator_with_return_value, warn_on_generator_with_return_value
|
||||
|
|
@ -254,3 +255,10 @@ https://example.org
|
|||
warn_on_generator_with_return_value(None, top_level_return_none)
|
||||
self.assertEqual(len(w), 1)
|
||||
self.assertIn('Unable to determine', str(w[0].message))
|
||||
|
||||
def test_partial(self):
|
||||
def cb(arg1, arg2):
|
||||
yield {}
|
||||
|
||||
partial_cb = partial(cb, arg1=42)
|
||||
assert not is_generator_with_return_value(partial_cb)
|
||||
|
|
|
|||
Loading…
Reference in New Issue