Workaround bug detecting MAKE_FUNCTION docstrings

This commit is contained in:
rocky
2020-06-26 07:17:31 -04:00
parent e3720515ae
commit 11be90758f
2 changed files with 16 additions and 2 deletions

View File

@@ -895,6 +895,12 @@ class SourceWalker(GenericASTTraversal, object):
doc_node = node[0]
if doc_node.attr:
docstring = doc_node.attr
if not isinstance(docstring, str):
# FIXME: we have mistakenly tagged something as a doc
# string in transform when it isn't one.
# The rule in n_mkfunc is pretty flaky.
self.prune()
return
else:
docstring = node[0].pattr

View File

@@ -95,10 +95,18 @@ class TreeTransform(GenericASTTraversal, object):
code = find_code_node(node, code_index).attr
mkfunc_pattr = node[-1].pattr
if isinstance(mkfunc_pattr, tuple):
assert len(mkfunc_pattr, 4) and isinstance(mkfunc_pattr, int)
is_closure = node[-1].pattr[3] != 0
else:
# FIXME: This is what we had before. It is hoaky and probably wrong.
is_closure = mkfunc_pattr == "closure"
if (
node[-1].pattr != "closure"
(not is_closure)
and len(code.co_consts) > 0
and code.co_consts[0] is not None
and isinstance(code.co_consts[0], str)
):
docstring_node = SyntaxTree(
"docstring", [Token("LOAD_STR", has_arg=True, pattr=code.co_consts[0])]