@@ -4164,9 +4164,8 @@ type_new_set_name(const type_new_ctx *ctx, PyTypeObject *type)
41644164
41654165/* Set __module__ in the dict */
41664166static int
4167- type_new_set_module (PyTypeObject * type )
4167+ type_new_set_module (PyObject * dict )
41684168{
4169- PyObject * dict = lookup_tp_dict (type );
41704169 int r = PyDict_Contains (dict , & _Py_ID (__module__ ));
41714170 if (r < 0 ) {
41724171 return -1 ;
@@ -4193,10 +4192,9 @@ type_new_set_module(PyTypeObject *type)
41934192/* Set ht_qualname to dict['__qualname__'] if available, else to
41944193 __name__. The __qualname__ accessor will look for ht_qualname. */
41954194static int
4196- type_new_set_ht_name (PyTypeObject * type )
4195+ type_new_set_ht_name (PyTypeObject * type , PyObject * dict )
41974196{
41984197 PyHeapTypeObject * et = (PyHeapTypeObject * )type ;
4199- PyObject * dict = lookup_tp_dict (type );
42004198 PyObject * qualname ;
42014199 if (PyDict_GetItemRef (dict , & _Py_ID (__qualname__ ), & qualname ) < 0 ) {
42024200 return -1 ;
@@ -4225,9 +4223,8 @@ type_new_set_ht_name(PyTypeObject *type)
42254223 and is a string. The __doc__ accessor will first look for tp_doc;
42264224 if that fails, it will still look into __dict__. */
42274225static int
4228- type_new_set_doc (PyTypeObject * type )
4226+ type_new_set_doc (PyTypeObject * type , PyObject * dict )
42294227{
4230- PyObject * dict = lookup_tp_dict (type );
42314228 PyObject * doc = PyDict_GetItemWithError (dict , & _Py_ID (__doc__ ));
42324229 if (doc == NULL ) {
42334230 if (PyErr_Occurred ()) {
@@ -4261,9 +4258,8 @@ type_new_set_doc(PyTypeObject *type)
42614258
42624259
42634260static int
4264- type_new_staticmethod (PyTypeObject * type , PyObject * attr )
4261+ type_new_staticmethod (PyObject * dict , PyObject * attr )
42654262{
4266- PyObject * dict = lookup_tp_dict (type );
42674263 PyObject * func = PyDict_GetItemWithError (dict , attr );
42684264 if (func == NULL ) {
42694265 if (PyErr_Occurred ()) {
@@ -4289,9 +4285,8 @@ type_new_staticmethod(PyTypeObject *type, PyObject *attr)
42894285
42904286
42914287static int
4292- type_new_classmethod (PyTypeObject * type , PyObject * attr )
4288+ type_new_classmethod (PyObject * dict , PyObject * attr )
42934289{
4294- PyObject * dict = lookup_tp_dict (type );
42954290 PyObject * func = PyDict_GetItemWithError (dict , attr );
42964291 if (func == NULL ) {
42974292 if (PyErr_Occurred ()) {
@@ -4392,9 +4387,8 @@ type_new_set_slots(const type_new_ctx *ctx, PyTypeObject *type)
43924387
43934388/* store type in class' cell if one is supplied */
43944389static int
4395- type_new_set_classcell (PyTypeObject * type )
4390+ type_new_set_classcell (PyTypeObject * type , PyObject * dict )
43964391{
4397- PyObject * dict = lookup_tp_dict (type );
43984392 PyObject * cell = PyDict_GetItemWithError (dict , & _Py_ID (__classcell__ ));
43994393 if (cell == NULL ) {
44004394 if (PyErr_Occurred ()) {
@@ -4419,9 +4413,8 @@ type_new_set_classcell(PyTypeObject *type)
44194413}
44204414
44214415static int
4422- type_new_set_classdictcell (PyTypeObject * type )
4416+ type_new_set_classdictcell (PyObject * dict )
44234417{
4424- PyObject * dict = lookup_tp_dict (type );
44254418 PyObject * cell = PyDict_GetItemWithError (dict , & _Py_ID (__classdictcell__ ));
44264419 if (cell == NULL ) {
44274420 if (PyErr_Occurred ()) {
@@ -4452,30 +4445,33 @@ type_new_set_attrs(const type_new_ctx *ctx, PyTypeObject *type)
44524445 return -1 ;
44534446 }
44544447
4455- if (type_new_set_module (type ) < 0 ) {
4448+ PyObject * dict = lookup_tp_dict (type );
4449+ assert (dict );
4450+
4451+ if (type_new_set_module (dict ) < 0 ) {
44564452 return -1 ;
44574453 }
44584454
4459- if (type_new_set_ht_name (type ) < 0 ) {
4455+ if (type_new_set_ht_name (type , dict ) < 0 ) {
44604456 return -1 ;
44614457 }
44624458
4463- if (type_new_set_doc (type ) < 0 ) {
4459+ if (type_new_set_doc (type , dict ) < 0 ) {
44644460 return -1 ;
44654461 }
44664462
44674463 /* Special-case __new__: if it's a plain function,
44684464 make it a static function */
4469- if (type_new_staticmethod (type , & _Py_ID (__new__ )) < 0 ) {
4465+ if (type_new_staticmethod (dict , & _Py_ID (__new__ )) < 0 ) {
44704466 return -1 ;
44714467 }
44724468
44734469 /* Special-case __init_subclass__ and __class_getitem__:
44744470 if they are plain functions, make them classmethods */
4475- if (type_new_classmethod (type , & _Py_ID (__init_subclass__ )) < 0 ) {
4471+ if (type_new_classmethod (dict , & _Py_ID (__init_subclass__ )) < 0 ) {
44764472 return -1 ;
44774473 }
4478- if (type_new_classmethod (type , & _Py_ID (__class_getitem__ )) < 0 ) {
4474+ if (type_new_classmethod (dict , & _Py_ID (__class_getitem__ )) < 0 ) {
44794475 return -1 ;
44804476 }
44814477
@@ -4485,10 +4481,10 @@ type_new_set_attrs(const type_new_ctx *ctx, PyTypeObject *type)
44854481
44864482 type_new_set_slots (ctx , type );
44874483
4488- if (type_new_set_classcell (type ) < 0 ) {
4484+ if (type_new_set_classcell (type , dict ) < 0 ) {
44894485 return -1 ;
44904486 }
4491- if (type_new_set_classdictcell (type ) < 0 ) {
4487+ if (type_new_set_classdictcell (dict ) < 0 ) {
44924488 return -1 ;
44934489 }
44944490 return 0 ;
0 commit comments