diff --git a/cloudpickle/cloudpickle.py b/cloudpickle/cloudpickle.py index 4d532e5d..d8156155 100644 --- a/cloudpickle/cloudpickle.py +++ b/cloudpickle/cloudpickle.py @@ -96,6 +96,7 @@ _DYNAMIC_CLASS_TRACKER_LOCK = threading.Lock() PYPY = platform.python_implementation() == "PyPy" +GRAALPY = platform.python_implementation() == "GraalVM" builtin_code_type = None if PYPY: @@ -410,10 +411,15 @@ def _builtin_type(name): def _walk_global_ops(code): """Yield referenced name for global-referencing instructions in code.""" - for instr in dis.get_instructions(code): - op = instr.opcode - if op in GLOBAL_OPS: - yield instr.argval + if not GRAALPY: + for instr in dis.get_instructions(code): + op = instr.opcode + if op in GLOBAL_OPS: + yield instr.argval + else: + # GraalPy doesn't support disassembling bytecode, assume all names + # reference globals + yield from code.co_names def _extract_class_dict(cls): diff --git a/tests/cloudpickle_test.py b/tests/cloudpickle_test.py index 72aa132f..78ad74ea 100644 --- a/tests/cloudpickle_test.py +++ b/tests/cloudpickle_test.py @@ -190,6 +190,13 @@ def test_pickling_file_handles(self): out2 = pickle.loads(cloudpickle.dumps(out1, protocol=self.protocol)) self.assertEqual(out1, out2) + @pytest.mark.skipif( + platform.python_implementation() == "GraalVM", + reason=( + "GraalPy doesn't support disassembling bytecode, so globals " + "cannot be distinguished from other names." + ), + ) def test_func_globals(self): class Unpicklable: def __reduce__(self): @@ -925,7 +932,7 @@ def test_builtin_classmethod(self): @pytest.mark.skipif( ( sys.version_info >= (3, 10, 8) - and platform.python_implementation() == "CPython" + and platform.python_implementation() in ("CPython", "GraalVM") ), reason=( "CPython dropped support for pickling classmethod_descriptor,"