mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
gh-95196: Disable incorrect pickling of the C implemented classmethod descriptors (GH-96383)
This commit is contained in:
parent
f8cbd79d32
commit
77f0249308
3 changed files with 20 additions and 1 deletions
|
@ -2776,6 +2776,15 @@ class AbstractPickleTests:
|
||||||
unpickled = self.loads(self.dumps(method, proto))
|
unpickled = self.loads(self.dumps(method, proto))
|
||||||
self.assertEqual(method(obj), unpickled(obj))
|
self.assertEqual(method(obj), unpickled(obj))
|
||||||
|
|
||||||
|
descriptors = (
|
||||||
|
PyMethodsTest.__dict__['cheese'], # static method descriptor
|
||||||
|
PyMethodsTest.__dict__['wine'], # class method descriptor
|
||||||
|
)
|
||||||
|
for proto in range(pickle.HIGHEST_PROTOCOL + 1):
|
||||||
|
for descr in descriptors:
|
||||||
|
with self.subTest(proto=proto, descr=descr):
|
||||||
|
self.assertRaises(TypeError, self.dumps, descr, proto)
|
||||||
|
|
||||||
def test_c_methods(self):
|
def test_c_methods(self):
|
||||||
global Subclass
|
global Subclass
|
||||||
class Subclass(tuple):
|
class Subclass(tuple):
|
||||||
|
@ -2811,6 +2820,15 @@ class AbstractPickleTests:
|
||||||
unpickled = self.loads(self.dumps(method, proto))
|
unpickled = self.loads(self.dumps(method, proto))
|
||||||
self.assertEqual(method(*args), unpickled(*args))
|
self.assertEqual(method(*args), unpickled(*args))
|
||||||
|
|
||||||
|
descriptors = (
|
||||||
|
bytearray.__dict__['maketrans'], # built-in static method descriptor
|
||||||
|
dict.__dict__['fromkeys'], # built-in class method descriptor
|
||||||
|
)
|
||||||
|
for proto in range(pickle.HIGHEST_PROTOCOL + 1):
|
||||||
|
for descr in descriptors:
|
||||||
|
with self.subTest(proto=proto, descr=descr):
|
||||||
|
self.assertRaises(TypeError, self.dumps, descr, proto)
|
||||||
|
|
||||||
def test_compat_pickle(self):
|
def test_compat_pickle(self):
|
||||||
tests = [
|
tests = [
|
||||||
(range(1, 7), '__builtin__', 'xrange'),
|
(range(1, 7), '__builtin__', 'xrange'),
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Disable incorrect pickling of the C implemented classmethod descriptors.
|
|
@ -776,7 +776,7 @@ PyTypeObject PyClassMethodDescr_Type = {
|
||||||
0, /* tp_weaklistoffset */
|
0, /* tp_weaklistoffset */
|
||||||
0, /* tp_iter */
|
0, /* tp_iter */
|
||||||
0, /* tp_iternext */
|
0, /* tp_iternext */
|
||||||
descr_methods, /* tp_methods */
|
0, /* tp_methods */
|
||||||
descr_members, /* tp_members */
|
descr_members, /* tp_members */
|
||||||
method_getset, /* tp_getset */
|
method_getset, /* tp_getset */
|
||||||
0, /* tp_base */
|
0, /* tp_base */
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue