You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-03 00:45:53 +08:00
Attempt to fix annotation bugs
This commit is contained in:
@@ -14,6 +14,7 @@ import click
|
||||
from xdis.version_info import version_tuple_to_str
|
||||
|
||||
from uncompyle6.main import main, status_msg
|
||||
from uncompyle6.verify import VerifyCmpError
|
||||
from uncompyle6.version import __version__
|
||||
|
||||
program = "uncompyle6"
|
||||
@@ -157,12 +158,20 @@ def main_bin(
|
||||
|
||||
version_tuple = sys.version_info[0:2]
|
||||
if not ((3, 3) <= version_tuple < (3, 6)):
|
||||
print(
|
||||
"Error: This version of the {program} runs from Python 3.3 to 3.5."
|
||||
"You need another branch of this code for other Python versions."
|
||||
" \n\tYou have version: %s." % version_tuple_to_str()
|
||||
)
|
||||
sys.exit(-1)
|
||||
if version_tuple > (3, 5):
|
||||
print(
|
||||
"This version of the {program} is tailored for Python 3.3 to 3.5.\n"
|
||||
"It may run on other versions, but there are problems, switch to code "
|
||||
"from another branch.\n"
|
||||
"You have version: %s." % version_tuple_to_str()
|
||||
)
|
||||
else:
|
||||
print(
|
||||
"Error: This version of the {program} runs from Python 3.3 to 3.5.\n"
|
||||
"You need another branch of this code for other Python versions."
|
||||
" \n\tYou have version: %s." % version_tuple_to_str()
|
||||
)
|
||||
sys.exit(-1)
|
||||
|
||||
numproc = 0
|
||||
out_base = None
|
||||
@@ -242,7 +251,7 @@ def main_bin(
|
||||
sys.exit(2)
|
||||
except KeyboardInterrupt:
|
||||
pass
|
||||
except verify.VerifyCmpError:
|
||||
except VerifyCmpError:
|
||||
raise
|
||||
else:
|
||||
from multiprocessing import Process, Queue
|
||||
|
@@ -382,25 +382,14 @@ def main(
|
||||
check_type = "syntax check"
|
||||
if do_verify == "run":
|
||||
check_type = "run"
|
||||
if PYTHON_VERSION_TRIPLE >= (3, 7):
|
||||
result = subprocess.run(
|
||||
[sys.executable, deparsed_object.f.name],
|
||||
capture_output=True,
|
||||
)
|
||||
valid = result.returncode == 0
|
||||
output = result.stdout.decode()
|
||||
if output:
|
||||
print(output)
|
||||
pass
|
||||
else:
|
||||
result = subprocess.run(
|
||||
[sys.executable, deparsed_object.f.name],
|
||||
)
|
||||
valid = result.returncode == 0
|
||||
pass
|
||||
return_code = subprocess.call(
|
||||
[sys.executable, deparsed_object.f.name],
|
||||
stdout=sys.stdout,
|
||||
stderr=sys.stderr,
|
||||
)
|
||||
valid = return_code == 0
|
||||
if not valid:
|
||||
print(result.stderr.decode())
|
||||
|
||||
sys.stderr.write("Got return code %d\n" % return_code)
|
||||
else:
|
||||
valid = syntax_check(deparsed_object.f.name)
|
||||
|
||||
|
@@ -1221,9 +1221,24 @@ class Python3Parser(PythonParser):
|
||||
)
|
||||
)
|
||||
else:
|
||||
rule = "mkfunc ::= %s%sload_closure LOAD_CODE LOAD_STR %s" % (
|
||||
kwargs_str,
|
||||
"pos_arg " * pos_args_count,
|
||||
if self.version == (3, 3):
|
||||
# 3.3 puts kwargs before pos_arg
|
||||
pos_kw_tuple = (
|
||||
("kwargs " * kw_args_count),
|
||||
("pos_arg " * pos_args_count),
|
||||
)
|
||||
else:
|
||||
# 3.4 and 3.5 puts pos_arg before kwargs
|
||||
pos_kw_tuple = (
|
||||
"pos_arg " * (pos_args_count),
|
||||
("kwargs " * kw_args_count),
|
||||
)
|
||||
rule = (
|
||||
"mkfunc ::= %s%s%s " "load_closure LOAD_CODE LOAD_STR %s"
|
||||
) % (
|
||||
pos_kw_tuple[0],
|
||||
pos_kw_tuple[1],
|
||||
"annotate_pair " * (annotate_args),
|
||||
opname,
|
||||
)
|
||||
self.add_unique_rule(rule, opname, token.attr, customize)
|
||||
@@ -1465,12 +1480,12 @@ class Python3Parser(PythonParser):
|
||||
)
|
||||
self.add_unique_rule(rule, opname, token.attr, customize)
|
||||
rule = (
|
||||
"mkfunc_annotate ::= %s%sannotate_tuple LOAD_CODE LOAD_STR %s"
|
||||
% (
|
||||
("pos_arg " * pos_args_count),
|
||||
("annotate_arg " * annotate_args),
|
||||
opname,
|
||||
)
|
||||
"mkfunc_annotate ::= %s%sannotate_tuple LOAD_CODE "
|
||||
"LOAD_STR %s"
|
||||
) % (
|
||||
("pos_arg " * pos_args_count),
|
||||
("annotate_arg " * annotate_args),
|
||||
opname,
|
||||
)
|
||||
if self.version >= (3, 3):
|
||||
if self.version == (3, 3):
|
||||
@@ -1480,29 +1495,19 @@ class Python3Parser(PythonParser):
|
||||
("pos_arg " * pos_args_count),
|
||||
)
|
||||
else:
|
||||
# 3.4 and 3.5puts pos_arg before kwargs
|
||||
# 3.4 and 3.5 puts pos_arg before kwargs
|
||||
pos_kw_tuple = (
|
||||
"pos_arg " * (pos_args_count),
|
||||
("kwargs " * kw_args_count),
|
||||
)
|
||||
rule = (
|
||||
"mkfunc_annotate ::= %s%s%sannotate_tuple LOAD_CODE LOAD_STR %s"
|
||||
% (
|
||||
pos_kw_tuple[0],
|
||||
pos_kw_tuple[1],
|
||||
("annotate_arg " * annotate_args),
|
||||
opname,
|
||||
)
|
||||
)
|
||||
self.add_unique_rule(rule, opname, token.attr, customize)
|
||||
rule = (
|
||||
"mkfunc_annotate ::= %s%s%sannotate_tuple LOAD_CODE LOAD_STR %s"
|
||||
% (
|
||||
pos_kw_tuple[0],
|
||||
pos_kw_tuple[1],
|
||||
("annotate_arg " * annotate_args),
|
||||
opname,
|
||||
)
|
||||
"mkfunc_annotate ::= %s%s%sannotate_tuple LOAD_CODE "
|
||||
"LOAD_STR %s"
|
||||
) % (
|
||||
pos_kw_tuple[0],
|
||||
pos_kw_tuple[1],
|
||||
("annotate_arg " * annotate_args),
|
||||
opname,
|
||||
)
|
||||
else:
|
||||
rule = (
|
||||
|
@@ -16,6 +16,12 @@ class Python33Parser(Python32Parser):
|
||||
stmt ::= genexpr_func
|
||||
"""
|
||||
|
||||
def p_33_function_def(self, args):
|
||||
"""
|
||||
annotate_pair ::= LOAD_NAME LOAD_CONST
|
||||
|
||||
"""
|
||||
|
||||
def customize_grammar_rules(self, tokens, customize):
|
||||
self.remove_rules(
|
||||
"""
|
||||
|
@@ -1,4 +1,4 @@
|
||||
# Copyright (c) 2017, 2021-2022 by Rocky Bernstein
|
||||
# Copyright (c) 2017, 2021-2022, 2024 by Rocky Bernstein
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
@@ -22,21 +22,22 @@ This sets up opcodes Python's 3.5 and calls a generalized
|
||||
scanner routine for Python 3.
|
||||
"""
|
||||
|
||||
from __future__ import print_function
|
||||
# bytecode verification, verify(), uses JUMP_OPs from here
|
||||
from xdis.opcodes import opcode_35 as opc
|
||||
|
||||
from uncompyle6.scanners.scanner3 import Scanner3
|
||||
|
||||
# bytecode verification, verify(), uses JUMP_OPs from here
|
||||
from xdis.opcodes import opcode_35 as opc
|
||||
JUMP_OPS = opc.JUMP_OPS
|
||||
|
||||
class Scanner35(Scanner3):
|
||||
|
||||
class Scanner35(Scanner3):
|
||||
def __init__(self, show_asm=None, is_pypy=False):
|
||||
Scanner3.__init__(self, (3, 5), show_asm, is_pypy)
|
||||
return
|
||||
|
||||
pass
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
from xdis.version_info import PYTHON_VERSION_TRIPLE, version_tuple_to_str
|
||||
|
||||
|
@@ -318,12 +318,6 @@ class Scanner37Base(Scanner):
|
||||
argval = inst.argval
|
||||
op = inst.opcode
|
||||
|
||||
if inst.opname == "EXTENDED_ARG":
|
||||
# FIXME: The EXTENDED_ARG is used to signal annotation
|
||||
# parameters
|
||||
if i + 1 < n and self.insts[i + 1].opcode != self.opc.MAKE_FUNCTION:
|
||||
continue
|
||||
|
||||
if inst.offset in jump_targets:
|
||||
jump_idx = 0
|
||||
# We want to process COME_FROMs to the same offset to be in *descending*
|
||||
|
Reference in New Issue
Block a user