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 505f7c03..61aa0c01 100644 Binary files a/test/bytecode_2.7/00_docstring.pyc and b/test/bytecode_2.7/00_docstring.pyc differ diff --git a/test/bytecode_3.6/00_docstring.pyc b/test/bytecode_3.6/00_docstring.pyc index 749c05cb..b7600421 100644 Binary files a/test/bytecode_3.6/00_docstring.pyc and b/test/bytecode_3.6/00_docstring.pyc differ 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)