Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bytecode for Python 3.12 #327

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion js2py/translators/translating_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ def TryStatement(type, block, handler, handlers, guardedHandlers, finalizer):
if handler:
identifier = handler['param']['name']
holder = 'PyJsHolder_%s_%d' % (to_hex(identifier),
random.randrange(1e8))
random.randrange(six.integer_types[-1](1e8)))
identifier = repr(identifier)
result += 'except PyJsException as PyJsTempException:\n'
# fill in except ( catch ) block and remember to recover holder variable to its previous state
Expand Down
4 changes: 3 additions & 1 deletion js2py/utils/injector.py
felixonmars marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# Opcode constants used for comparison and replacecment
LOAD_FAST = opcode.opmap['LOAD_FAST']
LOAD_GLOBAL = opcode.opmap['LOAD_GLOBAL']
LOAD_ATTR = opcode.opmap['LOAD_ATTR']
STORE_FAST = opcode.opmap['STORE_FAST']


Expand Down Expand Up @@ -79,6 +80,7 @@ def append_arguments(code_obj, new_locals):
(co_names.index(name), varnames.index(name)) for name in new_locals)

is_new_bytecode = sys.version_info >= (3, 11)
is_new_load_attr = sys.version_info >= (3, 12)
# Now we modify the actual bytecode
modified = []
drop_future_cache = False
Expand All @@ -97,7 +99,7 @@ def append_arguments(code_obj, new_locals):
# it's one of the globals that we are replacing. Either way,
# update its arg using the appropriate dict.
drop_future_cache = False
if inst.opcode == LOAD_GLOBAL:
if inst.opcode == LOAD_GLOBAL or (is_new_load_attr and inst.opcode == LOAD_ATTR):
idx = inst.arg
if is_new_bytecode:
idx = idx // 2
Expand Down