diff --git a/test/bytecode_2.5/01_rel_import.pyc b/test/bytecode_2.5/01_rel_import.pyc new file mode 100644 index 000000000..eff913781 Binary files /dev/null and b/test/bytecode_2.5/01_rel_import.pyc differ diff --git a/test/bytecode_2.6/01_rel_import.pyc b/test/bytecode_2.6/01_rel_import.pyc new file mode 100644 index 000000000..d399eadf3 Binary files /dev/null and b/test/bytecode_2.6/01_rel_import.pyc differ diff --git a/test/bytecode_2.7/01_rel_import.pyc b/test/bytecode_2.7/01_rel_import.pyc index 46c146daa..8e516b37d 100644 Binary files a/test/bytecode_2.7/01_rel_import.pyc and b/test/bytecode_2.7/01_rel_import.pyc differ diff --git a/test/simple_source/stmts/01_rel_import.py b/test/simple_source/stmts/01_rel_import.py index 77293b597..1dafdc546 100644 --- a/test/simple_source/stmts/01_rel_import.py +++ b/test/simple_source/stmts/01_rel_import.py @@ -1,2 +1,4 @@ # Tests relative imports from . import bogus +from .. import foo +from ..bar import baz diff --git a/uncompyle6/semantics/consts.py b/uncompyle6/semantics/consts.py index d094febf3..e62d5ea57 100644 --- a/uncompyle6/semantics/consts.py +++ b/uncompyle6/semantics/consts.py @@ -476,8 +476,17 @@ "kv2": ("%c: %c", 1, 2), "import": ("%|import %c\n", 2), "importlist": ("%C", (0, maxint, ", ")), - "import_from": ("%|from %[2]{pattr} import %c\n", (3, "importlist")), - "import_from_star": ("%|from %[2]{pattr} import *\n",), + + # Note: the below rule isn't really complete: + # n_import_from() smashes node[2].pattr + "import_from": ( + "%|from %[2]{pattr} import %c\n", + (3, "importlist") + ), + + "import_from_star": ( + "%|from %[2]{pattr} import *\n", + ), } diff --git a/uncompyle6/semantics/customize25.py b/uncompyle6/semantics/customize25.py index 911997a98..886e96331 100644 --- a/uncompyle6/semantics/customize25.py +++ b/uncompyle6/semantics/customize25.py @@ -48,3 +48,9 @@ def tryfinallystmt(node): node[1][0][0][0].kind = 'tf_tryelsestmt' self.default(node) self.n_tryfinallystmt = tryfinallystmt + + def n_import_from(node): + if node[0].pattr > 0: + node[2].pattr = ("." * node[0].pattr) + node[2].pattr + self.default(node) + self.n_import_from = n_import_from diff --git a/uncompyle6/semantics/customize26_27.py b/uncompyle6/semantics/customize26_27.py index 2e503c219..191966147 100644 --- a/uncompyle6/semantics/customize26_27.py +++ b/uncompyle6/semantics/customize26_27.py @@ -62,12 +62,7 @@ def n_call(node): self.n_call = n_call def n_import_from(node): - import_name = node[2] - if import_name == "IMPORT_NAME" and import_name.pattr == "": - fmt = "%|from . import %c\n" - self.template_engine( - (fmt, (3, "importlist")), node - ) - self.prune() + if node[0].pattr > 0: + node[2].pattr = ("." * node[0].pattr) + node[2].pattr self.default(node) self.n_import_from = n_import_from