@@ -2773,6 +2773,15 @@ def pie(self):
2773
2773
unpickled = self .loads (self .dumps (method , proto ))
2774
2774
self .assertEqual (method (obj ), unpickled (obj ))
2775
2775
2776
+ descriptors = (
2777
+ PyMethodsTest .__dict__ ['cheese' ], # static method descriptor
2778
+ PyMethodsTest .__dict__ ['wine' ], # class method descriptor
2779
+ )
2780
+ for proto in range (pickle .HIGHEST_PROTOCOL + 1 ):
2781
+ for descr in descriptors :
2782
+ with self .subTest (proto = proto , descr = descr ):
2783
+ self .assertRaises (TypeError , self .dumps , descr , proto )
2784
+
2776
2785
def test_c_methods (self ):
2777
2786
global Subclass
2778
2787
class Subclass (tuple ):
@@ -2808,6 +2817,15 @@ class Nested(str):
2808
2817
unpickled = self .loads (self .dumps (method , proto ))
2809
2818
self .assertEqual (method (* args ), unpickled (* args ))
2810
2819
2820
+ descriptors = (
2821
+ bytearray .__dict__ ['maketrans' ], # built-in static method descriptor
2822
+ dict .__dict__ ['fromkeys' ], # built-in class method descriptor
2823
+ )
2824
+ for proto in range (pickle .HIGHEST_PROTOCOL + 1 ):
2825
+ for descr in descriptors :
2826
+ with self .subTest (proto = proto , descr = descr ):
2827
+ self .assertRaises (TypeError , self .dumps , descr , proto )
2828
+
2811
2829
def test_compat_pickle (self ):
2812
2830
tests = [
2813
2831
(range (1 , 7 ), '__builtin__' , 'xrange' ),
0 commit comments