You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-02 16:44:46 +08:00
Correct 2.5-7 relative import formatting
This commit is contained in:
BIN
test/bytecode_2.5/01_rel_import.pyc
Normal file
BIN
test/bytecode_2.5/01_rel_import.pyc
Normal file
Binary file not shown.
BIN
test/bytecode_2.6/01_rel_import.pyc
Normal file
BIN
test/bytecode_2.6/01_rel_import.pyc
Normal file
Binary file not shown.
Binary file not shown.
@@ -1,2 +1,4 @@
|
||||
# Tests relative imports
|
||||
from . import bogus
|
||||
from .. import foo
|
||||
from ..bar import baz
|
||||
|
@@ -476,8 +476,17 @@ TABLE_DIRECT = {
|
||||
"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",
|
||||
),
|
||||
}
|
||||
|
||||
|
||||
|
@@ -48,3 +48,9 @@ def customize_for_version25(self, version):
|
||||
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
|
||||
|
@@ -62,12 +62,7 @@ def customize_for_version26_27(self, version):
|
||||
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
|
||||
|
Reference in New Issue
Block a user