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
3 changes: 1 addition & 2 deletions python/pyspark/cloudpickle/cloudpickle.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@
import opcode
import pickle
from pickle import _getattribute as _pickle_getattribute
import platform
import struct
import sys
import threading
Expand Down Expand Up @@ -95,7 +94,7 @@
_DYNAMIC_CLASS_TRACKER_BY_ID = weakref.WeakValueDictionary()
_DYNAMIC_CLASS_TRACKER_LOCK = threading.Lock()

PYPY = platform.python_implementation() == "PyPy"
PYPY = sys.implementation.name == "pypy"

builtin_code_type = None
if PYPY:
Expand Down
17 changes: 17 additions & 0 deletions python/pyspark/tests/test_serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
import collections
import math
import pickle
import subprocess
import sys
import textwrap
import unittest

from pyspark import serializers
Expand Down Expand Up @@ -45,6 +47,21 @@


class SerializationTestCase(unittest.TestCase):
def test_cloudpickle_with_packaged_python_version(self):
script = textwrap.dedent(
"""
import sys
sys.version = sys.version.replace(" ", " | packaged by example | ", 1)

from pyspark import cloudpickle

func = cloudpickle.loads(cloudpickle.dumps(lambda x: x + 1))
assert func(1) == 2
"""
)
result = subprocess.run([sys.executable, "-c", script], capture_output=True, text=True)
self.assertEqual(result.returncode, 0, result.stdout + result.stderr)

def test_namedtuple(self):
from collections import namedtuple

Expand Down