Partial in is_generator_with_return_value

See path in #5592
This commit is contained in:
Alexandr N. Zamaraev 2022-08-16 11:03:37 +07:00 committed by GitHub
parent 52d93490f5
commit 13c5ad7e68
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 1 deletions

View File

@ -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):
code = re.sub(r"^[\t ]+", "", inspect.getsource(callable))
func = callable
while isinstance(func, partial):
func = func.func
code = re.sub(r"^[\t ]+", "", inspect.getsource(func))
tree = ast.parse(code)
for node in walk_callable(tree):
if isinstance(node, ast.Return) and not returns_none(node):