diff --git a/test/bytecode_3.5/04_importlist.pyc b/test/bytecode_3.5/04_importlist.pyc deleted file mode 100644 index 93bf84e5..00000000 Binary files a/test/bytecode_3.5/04_importlist.pyc and /dev/null differ diff --git a/test/bytecode_3.5_run/04_importlist.pyc b/test/bytecode_3.5_run/04_importlist.pyc new file mode 100644 index 00000000..f00b0335 Binary files /dev/null and b/test/bytecode_3.5_run/04_importlist.pyc differ diff --git a/test/bytecode_3.6/04_importlist.pyc b/test/bytecode_3.6/04_importlist.pyc deleted file mode 100644 index 5cf5c8d5..00000000 Binary files a/test/bytecode_3.6/04_importlist.pyc and /dev/null differ diff --git a/test/bytecode_3.6_run/04_importlist.pyc b/test/bytecode_3.6_run/04_importlist.pyc new file mode 100644 index 00000000..4f035bd2 Binary files /dev/null and b/test/bytecode_3.6_run/04_importlist.pyc differ diff --git a/test/bytecode_3.7/04_importlist.pyc b/test/bytecode_3.7/04_importlist.pyc deleted file mode 100644 index 61543575..00000000 Binary files a/test/bytecode_3.7/04_importlist.pyc and /dev/null differ diff --git a/test/bytecode_3.7_run/04_importlist.pyc b/test/bytecode_3.7_run/04_importlist.pyc new file mode 100644 index 00000000..cb315bef Binary files /dev/null and b/test/bytecode_3.7_run/04_importlist.pyc differ diff --git a/test/bytecode_3.8_run/04_importlist.pyc b/test/bytecode_3.8_run/04_importlist.pyc new file mode 100644 index 00000000..bbb514a8 Binary files /dev/null and b/test/bytecode_3.8_run/04_importlist.pyc differ diff --git a/test/simple_source/bug35/04_importlist.py b/test/simple_source/bug35/04_importlist.py index fa9e48c2..e941f5bf 100644 --- a/test/simple_source/bug35/04_importlist.py +++ b/test/simple_source/bug35/04_importlist.py @@ -1,7 +1,14 @@ +# From 3.7 test_cmath.py # Had bug in 3.x in not having semantic importlist rule -def main(osp, Mfile, mainpyfile, dbg=None): - try: - from xdis import load_module, PYTHON_VERSION, IS_PYPY - return PYTHON_VERSION, IS_PYPY, load_module - except: - pass +# bug is treating "import as" as "from xx import" while +# still being able to hand "from xx import" properly + +# RUNNABLE! +import os.path as osp +from sys import path +from os import sep, name + +assert osp.basename("a") +assert path +assert sep +assert name diff --git a/uncompyle6/parsers/parse37.py b/uncompyle6/parsers/parse37.py index 3c405733..0ddfcd64 100644 --- a/uncompyle6/parsers/parse37.py +++ b/uncompyle6/parsers/parse37.py @@ -598,6 +598,9 @@ class Python37Parser(Python37BaseParser): # Where does the POP_TOP really belong? import37 ::= import POP_TOP + alias ::= IMPORT_NAME_ATTR IMPORT_FROM store + alias ::= IMPORT_NAME_ATTR attributes store + import_from ::= LOAD_CONST LOAD_CONST IMPORT_NAME_ATTR importlist POP_TOP async_for_stmt ::= setup_loop expr GET_AITER diff --git a/uncompyle6/scanners/scanner37base.py b/uncompyle6/scanners/scanner37base.py index 4c4fd911..b8c9775e 100644 --- a/uncompyle6/scanners/scanner37base.py +++ b/uncompyle6/scanners/scanner37base.py @@ -358,6 +358,10 @@ class Scanner37Base(Scanner): # other parts like n_LOAD_CONST in pysource.py for example. pattr = const pass + elif opname == "IMPORT_NAME": + if "." in inst.argval: + opname = "IMPORT_NAME_ATTR" + pass elif opname in ("MAKE_FUNCTION", "MAKE_CLOSURE"): flags = argval opname = "MAKE_FUNCTION_%d" % (flags) @@ -888,6 +892,7 @@ class Scanner37Base(Scanner): elif op in self.setup_opts_no_loop: count_SETUP_ += 1 + if __name__ == "__main__": from uncompyle6 import PYTHON_VERSION diff --git a/uncompyle6/semantics/customize37.py b/uncompyle6/semantics/customize37.py index 2002cf21..73cd2230 100644 --- a/uncompyle6/semantics/customize37.py +++ b/uncompyle6/semantics/customize37.py @@ -73,3 +73,18 @@ def customize_for_version37(self, version): 'testfalse_not_and': ( "not (%c)", 0 ), }) + + def n_import_from(node): + relative_path_index = 0 + if node[relative_path_index].pattr > 0: + node[2].pattr = ("." * node[relative_path_index].pattr) + node[2].pattr + if isinstance(node[1].pattr, tuple): + imports = node[1].pattr + for pattr in imports: + node[1].pattr = pattr + self.default(node) + return + self.default(node) + + self.n_import_from = n_import_from + self.n_import_from_star = n_import_from diff --git a/uncompyle6/semantics/make_function2.py b/uncompyle6/semantics/make_function2.py index 5b10fbbd..10fd0e87 100644 --- a/uncompyle6/semantics/make_function2.py +++ b/uncompyle6/semantics/make_function2.py @@ -43,9 +43,6 @@ def make_function2(self, node, is_lambda, nested=1, code_node=None): This code is specialied for Python 2. """ - # FIXME: call make_function3 if we are self.version >= 3.0 - # and then simplify the below. - def build_param(ast, name, default): """build parameters: - handle defaults