@@ -3287,6 +3287,36 @@ save_global(PicklerObject *self, PyObject *obj, PyObject *name)
32873287 return status ;
32883288}
32893289
3290+ static int
3291+ save_singleton_type (PicklerObject * self , PyObject * obj , PyObject * singleton )
3292+ {
3293+ PyObject * reduce_value ;
3294+ int status ;
3295+
3296+ reduce_value = Py_BuildValue ("O(O)" , & PyType_Type , singleton );
3297+ if (reduce_value == NULL ) {
3298+ return -1 ;
3299+ }
3300+ status = save_reduce (self , reduce_value , obj );
3301+ Py_DECREF (reduce_value );
3302+ return status ;
3303+ }
3304+
3305+ static int
3306+ save_type (PicklerObject * self , PyObject * obj )
3307+ {
3308+ if (obj == (PyObject * )& PyNone_Type ) {
3309+ return save_singleton_type (self , obj , Py_None );
3310+ }
3311+ else if (obj == (PyObject * )& PyEllipsis_Type ) {
3312+ return save_singleton_type (self , obj , Py_Ellipsis );
3313+ }
3314+ else if (obj == (PyObject * )& PyNotImplemented_Type ) {
3315+ return save_singleton_type (self , obj , Py_NotImplemented );
3316+ }
3317+ return save_global (self , obj , NULL );
3318+ }
3319+
32903320static int
32913321save_pers (PicklerObject * self , PyObject * obj , PyObject * func )
32923322{
@@ -3696,7 +3726,7 @@ save(PicklerObject *self, PyObject *obj, int pers_save)
36963726 goto done ;
36973727 }
36983728 else if (type == & PyType_Type ) {
3699- status = save_global (self , obj , NULL );
3729+ status = save_type (self , obj );
37003730 goto done ;
37013731 }
37023732 else if (type == & PyFunction_Type ) {
0 commit comments