Skip to content
Closed
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
2 changes: 1 addition & 1 deletion python/pyspark/cloudpickle/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

__doc__ = cloudpickle.__doc__

__version__ = "3.1.1"
__version__ = "3.1.2"

__all__ = [ # noqa
"__version__",
Expand Down
19 changes: 13 additions & 6 deletions python/pyspark/cloudpickle/cloudpickle.py
Original file line number Diff line number Diff line change
Expand Up @@ -783,6 +783,12 @@ def _class_getstate(obj):

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

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

return (clsdict, {})


Expand Down Expand Up @@ -1190,6 +1196,10 @@ def _class_setstate(obj, state):
for subclass in registry:
obj.register(subclass)

# PEP-649/749: During pickling, we excluded the __annotate_func__ attribute but it
# will be created by Python. Subsequently, annotations will be recreated when
# __annotations__ is accessed.

return obj


Expand Down Expand Up @@ -1301,12 +1311,9 @@ def _function_getnewargs(self, func):
def dump(self, obj):
try:
return super().dump(obj)
except RuntimeError as e:
if len(e.args) > 0 and "recursion" in e.args[0]:
msg = "Could not pickle object as excessively deep recursion required."
raise pickle.PicklingError(msg) from e
else:
raise
except RecursionError as e:
msg = "Could not pickle object as excessively deep recursion required."
raise pickle.PicklingError(msg) from e

def __init__(self, file, protocol=None, buffer_callback=None):
if protocol is None:
Expand Down