Skip to content

Commit a1ce9b2

Browse files
committed
[SPARK-54269][PYTHON] Upgrade cloudpickle to 3.1.2 for Python 3.14
### What changes were proposed in this pull request? This PR aims to upgrade `cloudpickle` to 3.1.2. ### Why are the changes needed? To support Python 3.14 properly. - https://github.com/cloudpipe/cloudpickle/releases/tag/v3.1.2 - https://github.com/cloudpipe/cloudpickle/blob/master/CHANGES.md#312 > Fix pickling of abstract base classes containing type annotations for Python 3.14. (cloudpipe/cloudpickle#578) ### Does this PR introduce _any_ user-facing change? No, Python 3.14 support is not announced yet. ### How was this patch tested? Pass the CIs. ### Was this patch authored or co-authored using generative AI tooling? No. Closes apache#52964 from dongjoon-hyun/SPARK-54269. Authored-by: Dongjoon Hyun <[email protected]> Signed-off-by: Dongjoon Hyun <[email protected]>
1 parent 0623e84 commit a1ce9b2

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

python/pyspark/cloudpickle/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
__doc__ = cloudpickle.__doc__
55

6-
__version__ = "3.1.1"
6+
__version__ = "3.1.2"
77

88
__all__ = [ # noqa
99
"__version__",

python/pyspark/cloudpickle/cloudpickle.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -783,6 +783,12 @@ def _class_getstate(obj):
783783

784784
clsdict.pop("__dict__", None) # unpicklable property object
785785

786+
if sys.version_info >= (3, 14):
787+
# PEP-649/749: __annotate_func__ contains a closure that references the class
788+
# dict. We need to exclude it from pickling. Python will recreate it when
789+
# __annotations__ is accessed at unpickling time.
790+
clsdict.pop("__annotate_func__", None)
791+
786792
return (clsdict, {})
787793

788794

@@ -1190,6 +1196,10 @@ def _class_setstate(obj, state):
11901196
for subclass in registry:
11911197
obj.register(subclass)
11921198

1199+
# PEP-649/749: During pickling, we excluded the __annotate_func__ attribute but it
1200+
# will be created by Python. Subsequently, annotations will be recreated when
1201+
# __annotations__ is accessed.
1202+
11931203
return obj
11941204

11951205

@@ -1301,12 +1311,9 @@ def _function_getnewargs(self, func):
13011311
def dump(self, obj):
13021312
try:
13031313
return super().dump(obj)
1304-
except RuntimeError as e:
1305-
if len(e.args) > 0 and "recursion" in e.args[0]:
1306-
msg = "Could not pickle object as excessively deep recursion required."
1307-
raise pickle.PicklingError(msg) from e
1308-
else:
1309-
raise
1314+
except RecursionError as e:
1315+
msg = "Could not pickle object as excessively deep recursion required."
1316+
raise pickle.PicklingError(msg) from e
13101317

13111318
def __init__(self, file, protocol=None, buffer_callback=None):
13121319
if protocol is None:

0 commit comments

Comments
 (0)