summaryrefslogtreecommitdiffstats
path: root/Lib/test/pickletester.py
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2022-10-05 11:59:09 (GMT)
committerGitHub <noreply@github.com>2022-10-05 11:59:09 (GMT)
commit2b248b0ab58428ae9c6006c02808ae2241293da3 (patch)
treec0406334412719334e2795449adc8e0caf634823 /Lib/test/pickletester.py
parent73e3510bdb2762e371e8545f1a4c68b821fcdcf2 (diff)
downloadcpython-2b248b0ab58428ae9c6006c02808ae2241293da3.zip
cpython-2b248b0ab58428ae9c6006c02808ae2241293da3.tar.gz
cpython-2b248b0ab58428ae9c6006c02808ae2241293da3.tar.bz2
gh-95196: Disable incorrect pickling of the C implemented classmethod descriptors (GH-96383)
(cherry picked from commit 77f0249308de76401bf4f3c6a057789c92f862d1) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Diffstat (limited to 'Lib/test/pickletester.py')
-rw-r--r--Lib/test/pickletester.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/Lib/test/pickletester.py b/Lib/test/pickletester.py
index 21419e1..499f80a 100644
--- a/Lib/test/pickletester.py
+++ b/Lib/test/pickletester.py
@@ -2776,6 +2776,15 @@ class AbstractPickleTests:
unpickled = self.loads(self.dumps(method, proto))
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):
global Subclass
class Subclass(tuple):
@@ -2811,6 +2820,15 @@ class AbstractPickleTests:
unpickled = self.loads(self.dumps(method, proto))
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):
tests = [
(range(1, 7), '__builtin__', 'xrange'),