From 090570cd34fad588a116816cfaf609044390f0aa Mon Sep 17 00:00:00 2001 From: rocky Date: Sat, 14 Jan 2023 02:20:59 -0500 Subject: [PATCH] 3.4-3.5 MAKE_CLOSURE with annotate Docs lie about annnotation args. Slight adjustment here. More is probably needed. --- uncompyle6/parser.py | 2 +- uncompyle6/scanners/scanner3.py | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/uncompyle6/parser.py b/uncompyle6/parser.py index 016b22de..3ef8a5a0 100644 --- a/uncompyle6/parser.py +++ b/uncompyle6/parser.py @@ -199,7 +199,7 @@ class PythonParser(GenericASTBuilder): if instructions[finish].linestart: break pass - if start > 0: + if start >= 0: err_token = instructions[index] print("Instruction context:") for i in range(start, finish): diff --git a/uncompyle6/scanners/scanner3.py b/uncompyle6/scanners/scanner3.py index 127f739e..d723a060 100644 --- a/uncompyle6/scanners/scanner3.py +++ b/uncompyle6/scanners/scanner3.py @@ -626,10 +626,19 @@ class Scanner3(Scanner): pos_args, name_pair_args, annotate_args = parse_fn_counts( inst.argval ) + + correct_annotate_args = annotate_args + if opname == "MAKE_CLOSURE" and ((3, 4) <= self.version < (3, 6)) and annotate_args > 0: + # For some reason that I don't understand annotate_args is off by one + # here from what is documented in + # https://docs.python.org/3.4/library/dis.html#opcode-MAKE_CLOSURE + # However in parsing rule, we have already adjusted for the one-fewer annotate arg + correct_annotate_args -= 1 + pattr = "%d positional, %d keyword only, %d annotated" % ( pos_args, name_pair_args, - annotate_args, + correct_annotate_args, ) if name_pair_args > 0: # FIXME: this should probably be K_