From e172a8f3c0e94faa4ec23ad25832327f121a25df Mon Sep 17 00:00:00 2001 From: rocky Date: Sat, 2 Dec 2017 21:11:19 -0500 Subject: [PATCH] Fix docstring bug.. small sync with python 2.4 branch --- test/Makefile | 12 +++---- test/bytecode_2.7/00_docstring.pyc | Bin 571 -> 1117 bytes test/bytecode_3.6/00_docstring.pyc | Bin 484 -> 997 bytes test/simple_source/stmts/00_docstring.py | 15 +++++++++ uncompyle6/semantics/helper.py | 1 + uncompyle6/semantics/pysource.py | 39 +++++++++++++++++------ 6 files changed, 51 insertions(+), 16 deletions(-) diff --git a/test/Makefile b/test/Makefile index 00baf381..2e202070 100644 --- a/test/Makefile +++ b/test/Makefile @@ -182,19 +182,19 @@ check-bytecode-2.7: #: Check deparsing Python 3.0 check-bytecode-3.0: - $(PYTHON) test_pythonlib.py --bytecode-3.0 + $(PYTHON) test_pythonlib.py --bytecode-3.0 --weak-verify #: Check deparsing Python 3.1 check-bytecode-3.1: - $(PYTHON) test_pythonlib.py --bytecode-3.1 + $(PYTHON) test_pythonlib.py --bytecode-3.1 --weak-verify #: Check deparsing Python 3.2 check-bytecode-3.2: - $(PYTHON) test_pythonlib.py --bytecode-3.2 + $(PYTHON) test_pythonlib.py --bytecode-3.2 --weak-verify #: Check deparsing Python 3.3 check-bytecode-3.3: - $(PYTHON) test_pythonlib.py --bytecode-3.3 + $(PYTHON) test_pythonlib.py --bytecode-3.3 --weak-verify #: Check deparsing Python 3.4 check-bytecode-3.4: @@ -202,11 +202,11 @@ check-bytecode-3.4: #: Check deparsing Python 3.5 check-bytecode-3.5: - $(PYTHON) test_pythonlib.py --bytecode-3.5 + $(PYTHON) test_pythonlib.py --bytecode-3.5 --weak-verify #: Check deparsing Python 3.6 check-bytecode-3.6: - $(PYTHON) test_pythonlib.py --bytecode-3.6 + $(PYTHON) test_pythonlib.py --bytecode-3.6 --weak-verify #: short tests for bytecodes only for this version of Python check-native-short: diff --git a/test/bytecode_2.7/00_docstring.pyc b/test/bytecode_2.7/00_docstring.pyc index 505f7c03d793ff779136251afd51c04c775dab5b..61aa0c011f5ac6a70f534b28cd4dc8e53bef1012 100644 GIT binary patch literal 1117 zcmb_b&5qMB5O$hnp_O=tQ7V)am2A5ww4xQ#UO1p03a6@)<+a^5ki=0u;b&Leco5!^ z16Ri05V}>-N`NDeXRMiTzKLhT?~eyRR>PHK?F#68N!valp%`0{4A@sv0;YOi=`j_0 zC1mP^y-6N8_opN_O(~(uh15HfD_z4g_?Y1ik|>JSrNufcx9gIO(VcXcF8;)&3ka>} ztjTe-7(}W5gtXhH)JKu9}RIXTOg8*Zq!L8~&aBm8ef0Pulmg|3*~}pj~O2dW|T~ z=W`I&>Kb7Rvl&c}Io-LV*X(Q;tv_iAs4a3OP(W5fF-G@3bVtG-xxWi64ks6LFb0N~?=5 z=CCwO>!x&tBzuI$5VyD7S6zKTdT1EJ!j#$r+xJ;jX_a=kj>}TpCP$lWM3!qcn~Xsq z>Y_q2o{zli|LBP8{;!T$ByPg+Aqjd7BROA^%9gIZmu}|%c5oh1?2E#vCf9R6yRHdO JgMQc#e*%UY0<-`C delta 80 zcmcc1v71Gj`7bD=2Fpg*NsP>X8qAa5FiTFnXd%e~ Xl(fmsPbtkwwPOM)WC0RvjGW8>;%g9k diff --git a/test/bytecode_3.6/00_docstring.pyc b/test/bytecode_3.6/00_docstring.pyc index 749c05cbe46e129218e7313f6bbfc6f9302a97d2..b76004210227e2fe7871737a58eb96a32dcf21ef 100644 GIT binary patch literal 997 zcmah{O^(wr6n2`C%;12K7l(*Q1lEQs(#=L=bQ z!WUiKJK{{7J1%ikpV>3Lo zZgH9}F2X~u&SrdsD+E@Ee=*L#5$%W$%dde+^D>jvs7iBrWo&NE)p$&W;yW#I`DyDX zO8M?_oJ2e8q_$Tlw1r`Kh!#Oq>s|)+*Q8;GVSW(YvRvx7{vFfjXzZl9R zOBBwtN=R|j-1$2+8|$iYfec%MMiA~#X&rTWZ?TXtfVnDUO>Ew$Whq76@H#E8rKvJ& zh6zhEDW>BQFl%LAS_IFc+V%ex-#lt6eumaO>TWME&5Bc6cc*rJpxv)lyVQ+e_e}43 Su0)l|nM1~PPuJ`DJ^weKz~kBg delta 98 zcmaFL{)E}Vn3tEU&Mhl~hmnEdF#{4{0 diff --git a/test/simple_source/stmts/00_docstring.py b/test/simple_source/stmts/00_docstring.py index 194eadc9..35870773 100644 --- a/test/simple_source/stmts/00_docstring.py +++ b/test/simple_source/stmts/00_docstring.py @@ -5,3 +5,18 @@ def foo(): def bar(): r"""func placeholder - ' and with ('''\nstring\n''') and \"\"\"\nstring\n\"\"\" """ + +def baz(): + """ + ... '''>>> assert 1 == 1 + ... ''' + ... \""" + >>> exec test_data in m1.__dict__ + >>> exec test_data in m2.__dict__ + >>> m1.__dict__.update({"f2": m2._f, "g2": m2.g, "h2": m2.H}) + + Tests that objects outside m1 are excluded: + \""" + >>> t.rundict(m1.__dict__, 'rundict_test_pvt') # None are skipped. + TestResults(failed=0, attempted=8) + """ diff --git a/uncompyle6/semantics/helper.py b/uncompyle6/semantics/helper.py index f6a8c565..56c6d754 100644 --- a/uncompyle6/semantics/helper.py +++ b/uncompyle6/semantics/helper.py @@ -13,6 +13,7 @@ def print_docstring(self, indent, docstring): quote = '"""' else: quote = "'''" + docstring = docstring.replace("'''", "\\'''") except: return False self.write(indent) diff --git a/uncompyle6/semantics/pysource.py b/uncompyle6/semantics/pysource.py index 69ba98ef..bad23a1b 100644 --- a/uncompyle6/semantics/pysource.py +++ b/uncompyle6/semantics/pysource.py @@ -110,8 +110,6 @@ Python. # brackets, which makes the template_engine walk down to N[C] before # evaluating the escape code. -from __future__ import print_function - import sys from uncompyle6 import PYTHON3 @@ -1075,7 +1073,10 @@ class SourceWalker(GenericASTTraversal, object): return n = node[-1] elif node[-1] == 'del_stmt': - n = node[-3] if node[-2] == 'JUMP_BACK' else node[-2] + if node[-2] == 'JUMP_BACK': + n = node[-3] + else: + n = node[-2] assert n == 'list_iter' @@ -1093,7 +1094,10 @@ class SourceWalker(GenericASTTraversal, object): list_iter = node[-1] else: expr = n[1] - list_iter = node[-3] if node[-2] == 'JUMP_BACK' else node[-2] + if node[-2] == 'JUMP_BACK': + list_iter = node[-3] + else: + list_iter = node[-2] assert expr == 'expr' assert list_iter == 'list_iter' @@ -1144,7 +1148,10 @@ class SourceWalker(GenericASTTraversal, object): self.write( '[ ') expr = n[0] - list_iter = node[-2] if self.is_pypy and node[-1] == 'JUMP_BACK' else node[-1] + if self.is_pypy and node[-1] == 'JUMP_BACK': + list_iter = node[-2] + else: + list_iter = node[-1] assert expr == 'expr' assert list_iter == 'list_iter' @@ -1218,7 +1225,10 @@ class SourceWalker(GenericASTTraversal, object): self.write(' for ') self.preorder(ast[iter_index-1]) self.write(' in ') - iter_expr = node[2] if node[2] == 'expr' else node[-3] + if node[2] == 'expr': + iter_expr = node[2] + else: + iter_expr = node[-3] assert iter_expr == 'expr' self.preorder(iter_expr) self.preorder(ast[iter_index]) @@ -1226,7 +1236,10 @@ class SourceWalker(GenericASTTraversal, object): def n_generator_exp(self, node): self.write('(') - code_index = -6 if self.version > 3.2 else -5 + if self.version > 3.2: + code_index = -6 + else: + code_index = -5 self.comprehension_walk(node, iter_index=3, code_index=code_index) self.write(')') self.prune() @@ -1469,7 +1482,10 @@ class SourceWalker(GenericASTTraversal, object): break pass pass - subclass_info = node if node == 'classdefdeco2' else node[0] + if node == 'classdefdeco2': + subclass_info = node + else: + subclass_info = node[0] elif buildclass[1][0] == 'load_closure': # Python 3 with closures not functions load_closure = buildclass[1] @@ -1496,7 +1512,10 @@ class SourceWalker(GenericASTTraversal, object): subclass_code = buildclass[1][0].attr subclass_info = node[0] else: - buildclass = node if (node == 'classdefdeco2') else node[0] + if node == 'classdefdeco2': + buildclass = node + else: + buildclass = node[0] build_list = buildclass[1][0] if hasattr(buildclass[-3][0], 'attr'): subclass_code = buildclass[-3][0].attr @@ -2338,7 +2357,7 @@ def deparse_code(version, co, out=sys.stdout, showasm=None, showast=False, if __name__ == '__main__': def deparse_test(co): "This is a docstring" - sys_version = sys.version_info.major + (sys.version_info.minor / 10.0) + sys_version = float(sys.version[0:3]) deparsed = deparse_code(sys_version, co, showasm='after', showast=True) # deparsed = deparse_code(sys_version, co, showasm=None, showast=False, # showgrammar=True)