You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-03 00:45:53 +08:00
Go over docstring handling
This commit is contained in:
@@ -884,7 +884,11 @@ class SourceWalker(GenericASTTraversal, object):
|
||||
def n_docstring(self, node):
|
||||
|
||||
indent = self.indent
|
||||
docstring = node[0].pattr
|
||||
doc_node = node[0]
|
||||
if doc_node.attr:
|
||||
docstring = doc_node.attr
|
||||
else:
|
||||
docstring = node[0].pattr
|
||||
|
||||
quote = '"""'
|
||||
if docstring.find(quote) >= 0:
|
||||
|
@@ -26,7 +26,7 @@ from uncompyle6.semantics.consts import RETURN_NONE
|
||||
|
||||
def is_docstring(node):
|
||||
try:
|
||||
return node[0].kind == "assign" and node[0][1][0].pattr == "__doc__"
|
||||
return node.kind == "assign" and node[1][0].pattr == "__doc__"
|
||||
except:
|
||||
return False
|
||||
|
||||
@@ -397,7 +397,7 @@ class TreeTransform(GenericASTTraversal, object):
|
||||
# Disambiguate a string (expression) which appears as a "call_stmt" at
|
||||
# the beginning of a function versus a docstring. Seems pretty academic,
|
||||
# but this is Python.
|
||||
call_stmt = ast[0][0][0]
|
||||
call_stmt = ast[0][0]
|
||||
if is_not_docstring(call_stmt):
|
||||
call_stmt.kind = "string_at_beginning"
|
||||
call_stmt.transformed_by = "transform"
|
||||
@@ -414,7 +414,8 @@ class TreeTransform(GenericASTTraversal, object):
|
||||
"LOAD_STR",
|
||||
has_arg=True,
|
||||
offset=0,
|
||||
pattr=self.ast[i][0][0][0].pattr,
|
||||
attr=self.ast[i][0][0].attr,
|
||||
pattr=self.ast[i][0][0].pattr,
|
||||
)
|
||||
],
|
||||
)
|
||||
|
Reference in New Issue
Block a user