From b99859148a23c4a0aa7e0dc82f1eb80786fc8058 Mon Sep 17 00:00:00 2001 From: stepan Date: Wed, 17 Jun 2026 14:24:25 +0200 Subject: [PATCH] Fix GraalPy compatibility --- _pydevd_bundle/pydevd_bytecode_utils.py | 5 +++++ _pydevd_bundle/pydevd_collect_bytecode_info.py | 14 ++++++++++++-- _pydevd_bundle/pydevd_comm.py | 5 ++++- _pydevd_bundle/pydevd_constants.py | 1 + 4 files changed, 22 insertions(+), 3 deletions(-) diff --git a/_pydevd_bundle/pydevd_bytecode_utils.py b/_pydevd_bundle/pydevd_bytecode_utils.py index 8a470444..bdbd2fee 100644 --- a/_pydevd_bundle/pydevd_bytecode_utils.py +++ b/_pydevd_bundle/pydevd_bytecode_utils.py @@ -4,6 +4,11 @@ Note: not importable from Python 2. """ +from _pydevd_bundle.pydevd_constants import IS_GRAALPY + +if IS_GRAALPY: + raise ImportError("Smart step into bytecode utilities are not available on GraalPy.") + from _pydev_bundle import pydev_log from types import CodeType from _pydevd_frame_eval.vendored.bytecode.instr import _Variable, Label diff --git a/_pydevd_bundle/pydevd_collect_bytecode_info.py b/_pydevd_bundle/pydevd_collect_bytecode_info.py index 10ed50d9..da93e7c3 100644 --- a/_pydevd_bundle/pydevd_collect_bytecode_info.py +++ b/_pydevd_bundle/pydevd_collect_bytecode_info.py @@ -80,11 +80,21 @@ def debug(s): _Instruction = namedtuple("_Instruction", "opname, opcode, starts_line, argval, is_jump_target, offset, argrepr") +_warned_dis_unavailable = False def iter_instructions(co): - iter_in = dis.Bytecode(co) - iter_in = list(iter_in) + global _warned_dis_unavailable + + try: + iter_in = list(dis.Bytecode(co)) + except NotImplementedError: + if not _warned_dis_unavailable: + _warned_dis_unavailable = True + # Log once because this is a supported-but-reduced mode on GraalPy: the + # debugger stays usable, but bytecode-derived helpers are unavailable. + pydev_log.info("Bytecode inspection is unavailable in this runtime; disabling dis-based debugger helpers.") + return bytecode_to_instruction = {} for instruction in iter_in: diff --git a/_pydevd_bundle/pydevd_comm.py b/_pydevd_bundle/pydevd_comm.py index b993c7ff..65e5f7e2 100644 --- a/_pydevd_bundle/pydevd_comm.py +++ b/_pydevd_bundle/pydevd_comm.py @@ -106,7 +106,10 @@ from urllib.parse import quote_plus, unquote_plus import pydevconsole from _pydevd_bundle import pydevd_vars, pydevd_io, pydevd_reload -from _pydevd_bundle import pydevd_bytecode_utils +try: + from _pydevd_bundle import pydevd_bytecode_utils +except ImportError: + pydevd_bytecode_utils = None from _pydevd_bundle import pydevd_xml from _pydevd_bundle import pydevd_vm_type import sys diff --git a/_pydevd_bundle/pydevd_constants.py b/_pydevd_bundle/pydevd_constants.py index b73bd489..d77df58e 100644 --- a/_pydevd_bundle/pydevd_constants.py +++ b/_pydevd_bundle/pydevd_constants.py @@ -62,6 +62,7 @@ class DebugInfoHolder: LIBRARY_CODE_BASENAMES_STARTING_WITH = ("<",) IS_CPYTHON = platform.python_implementation() == "CPython" +IS_GRAALPY = sys.implementation.name == "graalpy" # Hold a reference to the original _getframe (because psyco will change that as soon as it's imported) IS_IRONPYTHON = sys.platform == "cli"