FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-95196: Disable incorrect pickling of the C implemented classmethod descriptors by serhiy-storchaka · Pull Request #96383 · python/cpython · GitHub

/ cpython Public
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .c  (1) .py  (1) .rst  (1) All 3 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
18 changes: 18 additions & 0 deletions Lib/test/pickletester.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -2776,6 +2776,15 @@ def pie(self):
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):
Expand Down Expand Up @@ -2811,6 +2820,15 @@ class Nested(str):
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'),
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Disable incorrect pickling of the C implemented classmethod descriptors.
2 changes: 1 addition & 1 deletion Objects/descrobject.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -776,7 +776,7 @@ PyTypeObject PyClassMethodDescr_Type = {
0, /* tp_weaklistoffset */
0, /* tp_iter */
0, /* tp_iternext */
descr_methods, /* tp_methods */
0, /* tp_methods */
descr_members, /* tp_members */
method_getset, /* tp_getset */
0, /* tp_base */
Expand Down

Back | FazBrowse Home | New Git URL