@@ -1759,8 +1759,6 @@ raise_dict_descr_error(PyObject *obj)
17591759static PyObject *
17601760subtype_dict (PyObject * obj , void * context )
17611761{
1762- PyObject * * dictptr ;
1763- PyObject * dict ;
17641762 PyTypeObject * base ;
17651763
17661764 base = get_builtin_base_with_dict (Py_TYPE (obj ));
@@ -1778,25 +1776,13 @@ subtype_dict(PyObject *obj, void *context)
17781776 }
17791777 return func (descr , obj , (PyObject * )(Py_TYPE (obj )));
17801778 }
1781-
1782- dictptr = _PyObject_GetDictPtr (obj );
1783- if (dictptr == NULL ) {
1784- PyErr_SetString (PyExc_AttributeError ,
1785- "This object has no __dict__" );
1786- return NULL ;
1787- }
1788- dict = * dictptr ;
1789- if (dict == NULL )
1790- * dictptr = dict = PyDict_New ();
1791- Py_XINCREF (dict );
1792- return dict ;
1779+ return PyObject_GenericGetDict (obj , context );
17931780}
17941781
17951782static int
17961783subtype_setdict (PyObject * obj , PyObject * value , void * context )
17971784{
1798- PyObject * * dictptr ;
1799- PyObject * dict ;
1785+ PyObject * dict , * * dictptr ;
18001786 PyTypeObject * base ;
18011787
18021788 base = get_builtin_base_with_dict (Py_TYPE (obj ));
@@ -1814,14 +1800,14 @@ subtype_setdict(PyObject *obj, PyObject *value, void *context)
18141800 }
18151801 return func (descr , obj , value );
18161802 }
1817-
1803+ /* Almost like PyObject_GenericSetDict, but allow __dict__ to be deleted. */
18181804 dictptr = _PyObject_GetDictPtr (obj );
18191805 if (dictptr == NULL ) {
18201806 PyErr_SetString (PyExc_AttributeError ,
18211807 "This object has no __dict__" );
18221808 return -1 ;
18231809 }
1824- if (value != NULL && !PyDict_Check (value )) {
1810+ if (!PyDict_Check (value )) {
18251811 PyErr_Format (PyExc_TypeError ,
18261812 "__dict__ must be set to a dictionary, "
18271813 "not a '%.200s'" , Py_TYPE (value )-> tp_name );
0 commit comments