@@ -2835,6 +2835,36 @@ save_notimplemented(PicklerObject *self, PyObject *obj)
28352835 return res ;
28362836}
28372837
2838+ static int
2839+ save_singleton_type (PicklerObject * self , PyObject * obj , PyObject * singleton )
2840+ {
2841+ PyObject * reduce_value ;
2842+ int status ;
2843+
2844+ reduce_value = Py_BuildValue ("O(O)" , & PyType_Type , singleton );
2845+ if (reduce_value == NULL ) {
2846+ return -1 ;
2847+ }
2848+ status = save_reduce (self , reduce_value , obj );
2849+ Py_DECREF (reduce_value );
2850+ return status ;
2851+ }
2852+
2853+ static int
2854+ save_type (PicklerObject * self , PyObject * obj )
2855+ {
2856+ if (obj == (PyObject * )& PyNone_Type ) {
2857+ return save_singleton_type (self , obj , Py_None );
2858+ }
2859+ else if (obj == (PyObject * )& PyEllipsis_Type ) {
2860+ return save_singleton_type (self , obj , Py_Ellipsis );
2861+ }
2862+ else if (obj == (PyObject * )& PyNotImplemented_Type ) {
2863+ return save_singleton_type (self , obj , Py_NotImplemented );
2864+ }
2865+ return save_global (self , obj , NULL );
2866+ }
2867+
28382868static int
28392869save_pers (PicklerObject * self , PyObject * obj , PyObject * func )
28402870{
@@ -3189,7 +3219,7 @@ save(PicklerObject *self, PyObject *obj, int pers_save)
31893219 goto done ;
31903220 }
31913221 else if (type == & PyType_Type ) {
3192- status = save_global (self , obj , NULL );
3222+ status = save_type (self , obj );
31933223 goto done ;
31943224 }
31953225 else if (type == & PyFunction_Type ) {
0 commit comments