You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-02 16:44:46 +08:00
Fix annotation transform for 3.7+
We were producing: ``` z: z: int = 5 on bytecode_3.7_run/02_var_annotate.pyc ``` because grammar went 5. sstmt ann_assign (4) transformed by n_stmts: ('%|%[2]{attr}: %c\n', 0) 0. ann_assign_init (3): ('%|%[2]{attr}: %c = %c\n', 0, 1) The "ann_assign" added "z:". Instead we have now: ``` 5. sstmt ann_assign_init (3) transformed by n_stmts: ('%|%[2]{attr}: %c = %c\n', 0, 1) ``` Also, in the previous statement which appears in the listing (but is not actually in the finaly tree) we had: 4. sstmt assign (2): ('%|%c = %p\n', -1, (0, 200)) 0. expr L. L. 7 26 LOAD_CONST 5 1. store So we now preface the node type with "deleted", e.g.: 4. deleted sstmt assign (2): ('%|%c = %p\n', -1, (0, 200)) 0. expr L. L. 7 26 LOAD_CONST 5 1. store to reduce confusion
This commit is contained in:
@@ -421,10 +421,15 @@ class TreeTransform(GenericASTTraversal, object):
|
||||
):
|
||||
annotate_var = ann_assign[-2]
|
||||
if annotate_var.attr == prev[-1][0].attr:
|
||||
node[i].kind = "deleted " + node[i].kind
|
||||
del new_stmts[-1]
|
||||
sstmt[0][0] = SyntaxTree(
|
||||
"ann_assign_init", [ann_assign[0], prev[0], annotate_var]
|
||||
)
|
||||
ann_assign_init = SyntaxTree(
|
||||
"ann_assign_init", [ann_assign[0], copy(prev[0]), annotate_var]
|
||||
)
|
||||
if sstmt[0] == "ann_assign":
|
||||
sstmt[0] = ann_assign_init
|
||||
else:
|
||||
sstmt[0][0] = ann_assing_init
|
||||
sstmt[0].transformed_by = "n_stmts"
|
||||
pass
|
||||
pass
|
||||
|
Reference in New Issue
Block a user