Skip to content

Commit 7468d72

Browse files
vstinnerogrisel
andauthored
Fix #544: Port to Python 3.14 (#545)
* Fix #544: Port to Python 3.14 * _getattribute() API changed in Python 3.14. * itertools.count() no longer supports pickle on Python 3.14: https://docs.python.org/dev/whatsnew/3.14.html#itertools * Fix annotations test. --------- Co-authored-by: Olivier Grisel <[email protected]>
1 parent caf55df commit 7468d72

File tree

4 files changed

+19
-7
lines changed

4 files changed

+19
-7
lines changed

.github/workflows/testing.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ jobs:
2929
strategy:
3030
matrix:
3131
os: [ubuntu-latest, windows-latest, macos-latest]
32-
python_version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13", "pypy-3.9"]
32+
python_version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13", "3.14-dev", "pypy-3.9"]
3333
exclude:
3434
# Do not test all minor versions on all platforms, especially if they
3535
# are not the oldest/newest supported versions

CHANGES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
In development
22
==============
33

4+
- Various fixes to support for Python 3.14 ([PR #545](
5+
https://github.com/cloudpipe/cloudpickle/pull/545)).
46

57
3.1.0
68
=====

cloudpickle/cloudpickle.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
import logging
6464
import opcode
6565
import pickle
66-
from pickle import _getattribute
66+
from pickle import _getattribute as _pickle_getattribute
6767
import platform
6868
import struct
6969
import sys
@@ -192,6 +192,14 @@ def _is_registered_pickle_by_value(module):
192192
return False
193193

194194

195+
if sys.version_info >= (3, 14):
196+
def _getattribute(obj, name):
197+
return _pickle_getattribute(obj, name.split('.'))
198+
else:
199+
def _getattribute(obj, name):
200+
return _pickle_getattribute(obj, name)[0]
201+
202+
195203
def _whichmodule(obj, name):
196204
"""Find the module an object belongs to.
197205
@@ -219,7 +227,7 @@ def _whichmodule(obj, name):
219227
):
220228
continue
221229
try:
222-
if _getattribute(module, name)[0] is obj:
230+
if _getattribute(module, name) is obj:
223231
return module_name
224232
except Exception:
225233
pass
@@ -293,7 +301,7 @@ def _lookup_module_and_qualname(obj, name=None):
293301
return None
294302

295303
try:
296-
obj2, parent = _getattribute(module, name)
304+
obj2 = _getattribute(module, name)
297305
except AttributeError:
298306
# obj was not found inside the module it points to
299307
return None

tests/cloudpickle_test.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2235,6 +2235,10 @@ def test_unhashable_function(self):
22352235
self.assertEqual(depickled_method("a"), 1)
22362236
self.assertEqual(depickled_method("b"), None)
22372237

2238+
@unittest.skipIf(
2239+
sys.version_info >= (3, 14),
2240+
"itertools.count() doesn't support pickle on Python 3.14+",
2241+
)
22382242
def test_itertools_count(self):
22392243
counter = itertools.count(1, step=2)
22402244

@@ -2279,11 +2283,9 @@ def g():
22792283
self.assertEqual(f2.__doc__, f.__doc__)
22802284

22812285
def test_wraps_preserves_function_annotations(self):
2282-
def f(x):
2286+
def f(x: int) -> float:
22832287
pass
22842288

2285-
f.__annotations__ = {"x": 1, "return": float}
2286-
22872289
@wraps(f)
22882290
def g(x):
22892291
f(x)

0 commit comments

Comments
 (0)