Address long-standing Python 2.6 try/except bug

Fixes #405
This commit is contained in:
rocky 2024-07-11 13:59:16 -04:00
parent b0b67e9f34
commit 6fe8a1d2ba
3 changed files with 38 additions and 0 deletions

Binary file not shown.

View File

@ -0,0 +1,34 @@
# Bug portion of Issue #405 https://github.com/rocky/python-uncompyle6/issues/405
# Bug was detecting if/else as the last item in a "try: .. except" block.
class Saveframe(object):
"""A saveframe. Use the classmethod from_scratch to create one."""
frame_list = {}
def frame_dict(self):
return
# Next line is 1477
def __setitem__(self, key, item):
# Next line is 1481
if isinstance(item, Saveframe):
try:
self.frame_list[key] = item
except TypeError:
if key in (self.frame_dict()):
dict((frame.name, frame) for frame in self.frame_list)
for pos, frame in enumerate(self.frame_list):
if frame.name == key:
self.frame_list[pos] = item
else:
raise KeyError(
"Saveframe with name '%s' does not exist and "
"therefore cannot be written to. Use the add_saveframe method to add new saveframes."
% key
)
# Next line is 1498
raise ValueError("You can only assign an entry to a saveframe splice.")
x = Saveframe()
x.__setitem__("foo", 5)

View File

@ -130,6 +130,10 @@ class Python26Parser(Python2Parser):
# Semantic actions want else_suitel to be at index 3
ifelsestmtl ::= testexpr c_stmts_opt cf_jb_cf_pop else_suitel
ifelsestmtc ::= testexpr c_stmts_opt ja_cf_pop else_suitec
ifelsestmt ::= testexpr stmts_opt ja_cf_pop else_suite
# The last except of a "try: ... except" can do this...
except_suite ::= stmts_opt COME_FROM JUMP_ABSOLUTE POP_TOP
# Semantic actions want suite_stmts_opt to be at index 3
with ::= expr setupwith SETUP_FINALLY suite_stmts_opt