Skip to content
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
14 changes: 10 additions & 4 deletions cloudpickle/cloudpickle.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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):
Expand Down
9 changes: 8 additions & 1 deletion tests/cloudpickle_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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,"
Expand Down