Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 77f0249

Browse filesBrowse files
gh-95196: Disable incorrect pickling of the C implemented classmethod descriptors (GH-96383)
1 parent f8cbd79 commit 77f0249
Copy full SHA for 77f0249

File tree

3 files changed

+20
-1
lines changed
Filter options

3 files changed

+20
-1
lines changed

‎Lib/test/pickletester.py

Copy file name to clipboardExpand all lines: Lib/test/pickletester.py
+18Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2776,6 +2776,15 @@ def pie(self):
27762776
unpickled = self.loads(self.dumps(method, proto))
27772777
self.assertEqual(method(obj), unpickled(obj))
27782778

2779+
descriptors = (
2780+
PyMethodsTest.__dict__['cheese'], # static method descriptor
2781+
PyMethodsTest.__dict__['wine'], # class method descriptor
2782+
)
2783+
for proto in range(pickle.HIGHEST_PROTOCOL + 1):
2784+
for descr in descriptors:
2785+
with self.subTest(proto=proto, descr=descr):
2786+
self.assertRaises(TypeError, self.dumps, descr, proto)
2787+
27792788
def test_c_methods(self):
27802789
global Subclass
27812790
class Subclass(tuple):
@@ -2811,6 +2820,15 @@ class Nested(str):
28112820
unpickled = self.loads(self.dumps(method, proto))
28122821
self.assertEqual(method(*args), unpickled(*args))
28132822

2823+
descriptors = (
2824+
bytearray.__dict__['maketrans'], # built-in static method descriptor
2825+
dict.__dict__['fromkeys'], # built-in class method descriptor
2826+
)
2827+
for proto in range(pickle.HIGHEST_PROTOCOL + 1):
2828+
for descr in descriptors:
2829+
with self.subTest(proto=proto, descr=descr):
2830+
self.assertRaises(TypeError, self.dumps, descr, proto)
2831+
28142832
def test_compat_pickle(self):
28152833
tests = [
28162834
(range(1, 7), '__builtin__', 'xrange'),
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Disable incorrect pickling of the C implemented classmethod descriptors.

‎Objects/descrobject.c

Copy file name to clipboardExpand all lines: Objects/descrobject.c
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -776,7 +776,7 @@ PyTypeObject PyClassMethodDescr_Type = {
776776
0, /* tp_weaklistoffset */
777777
0, /* tp_iter */
778778
0, /* tp_iternext */
779-
descr_methods, /* tp_methods */
779+
0, /* tp_methods */
780780
descr_members, /* tp_members */
781781
method_getset, /* tp_getset */
782782
0, /* tp_base */

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.