Skip to content

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

Merge branch 'master' into patch-1

Andrey Rahmatullinc20b76d98f37
diff --cc scrapy/utils/misc.py
index 2e25f6421,4d4fb9600..e0f7ca9e5
--- a/scrapy/utils/misc.py
+++ b/scrapy/utils/misc.py
@@@ -227,11 -226,14 +227,18 @@@ def is_generator_with_return_value(call
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
+
- code = re.sub(r"^[\t ]+", "", inspect.getsource(func))
++ src = inspect.getsource(func)
+ pattern = re.compile(r"(^[\t ]+)")
+ code = pattern.sub("", src)
+
+ match = pattern.match(src) # finds indentation
+ if match:
+ code = re.sub(f"\n{match.group(0)}", "\n", code) # remove indentation
+
tree = ast.parse(code)
for node in walk_callable(tree):
if isinstance(node, ast.Return) and not returns_none(node):