Another LOAD_STR/CONST isolation in < 3.0

This commit is contained in:
rocky
2019-06-08 11:40:48 -04:00
parent 59b012df6f
commit 9d47b99932
2 changed files with 8 additions and 3 deletions

View File

@@ -128,10 +128,10 @@ PASS = SyntaxTree('stmts',
[ SyntaxTree('stmt',
[ SyntaxTree('pass', [])])])])
ASSIGN_DOC_STRING = lambda doc_string: \
ASSIGN_DOC_STRING = lambda doc_string, doc_load: \
SyntaxTree('stmt',
[ SyntaxTree('assign',
[ SyntaxTree('expr', [ Token('LOAD_STR', pattr=doc_string) ]),
[ SyntaxTree('expr', [ Token(doc_load, pattr=doc_string) ]),
SyntaxTree('store', [ Token('STORE_NAME', pattr='__doc__')])
])])

View File

@@ -2331,9 +2331,14 @@ def code_deparse(co, out=sys.stdout, version=None, debug_opts=DEFAULT_DEBUG_OPTS
assert not nonlocals
if version >= 3.0:
load_op = 'LOAD_STR'
else:
load_op = 'LOAD_CONST'
# convert leading '__doc__ = "..." into doc string
try:
if deparsed.ast[0][0] == ASSIGN_DOC_STRING(co.co_consts[0]):
if deparsed.ast[0][0] == ASSIGN_DOC_STRING(co.co_consts[0], load_op):
print_docstring(deparsed, '', co.co_consts[0])
del deparsed.ast[0]
if deparsed.ast[-1] == RETURN_NONE: