@@ -926,8 +926,11 @@ PyObject_HasAttrString(PyObject *v, const char *name)
926926 return ok ;
927927}
928928
929- int
930- PyObject_SetAttrString (PyObject * v , const char * name , PyObject * w )
929+ // Forward declaration
930+ static int object_set_attr (PyObject * v , PyObject * name , PyObject * value );
931+
932+ static int
933+ object_set_attr_string (PyObject * v , const char * name , PyObject * w )
931934{
932935 PyObject * s ;
933936 int res ;
@@ -937,15 +940,32 @@ PyObject_SetAttrString(PyObject *v, const char *name, PyObject *w)
937940 s = PyUnicode_InternFromString (name );
938941 if (s == NULL )
939942 return -1 ;
940- res = PyObject_SetAttr (v , s , w );
943+ res = object_set_attr (v , s , w );
941944 Py_XDECREF (s );
942945 return res ;
943946}
944947
948+ int
949+ PyObject_SetAttrString (PyObject * v , const char * name , PyObject * w )
950+ {
951+ if (w == NULL
952+ #ifndef Py_DEBUG
953+ && _Py_GetConfig ()-> dev_mode
954+ #endif
955+ && PyErr_WarnEx (PyExc_DeprecationWarning ,
956+ "PyObject_SetAttrString(v, name, NULL) is deprecated: "
957+ "use PyObject_DelAttrString(v, name) instead" ,
958+ 1 ) < 0 )
959+ {
960+ return -1 ;
961+ }
962+ return object_set_attr_string (v , name , w );
963+ }
964+
945965int
946966PyObject_DelAttrString (PyObject * v , const char * name )
947967{
948- return PyObject_SetAttrString (v , name , NULL );
968+ return object_set_attr_string (v , name , NULL );
949969}
950970
951971int
@@ -1156,8 +1176,8 @@ PyObject_HasAttr(PyObject *v, PyObject *name)
11561176 return 1 ;
11571177}
11581178
1159- int
1160- PyObject_SetAttr (PyObject * v , PyObject * name , PyObject * value )
1179+ static int
1180+ object_set_attr (PyObject * v , PyObject * name , PyObject * value )
11611181{
11621182 PyTypeObject * tp = Py_TYPE (v );
11631183 int err ;
@@ -1205,10 +1225,27 @@ PyObject_SetAttr(PyObject *v, PyObject *name, PyObject *value)
12051225 return -1 ;
12061226}
12071227
1228+ int
1229+ PyObject_SetAttr (PyObject * v , PyObject * name , PyObject * value )
1230+ {
1231+ if (value == NULL
1232+ #ifndef Py_DEBUG
1233+ && _Py_GetConfig ()-> dev_mode
1234+ #endif
1235+ && PyErr_WarnEx (PyExc_DeprecationWarning ,
1236+ "PyObject_SetAttr(v, name, NULL) is deprecated: "
1237+ "use PyObject_DelAttr(v, name) instead" ,
1238+ 1 ) < 0 )
1239+ {
1240+ return -1 ;
1241+ }
1242+ return object_set_attr (v , name , value );
1243+ }
1244+
12081245int
12091246PyObject_DelAttr (PyObject * v , PyObject * name )
12101247{
1211- return PyObject_SetAttr (v , name , NULL );
1248+ return object_set_attr (v , name , NULL );
12121249}
12131250
12141251PyObject * *
0 commit comments