@@ -4144,9 +4144,8 @@ type_new_set_name(const type_new_ctx *ctx, PyTypeObject *type)
4144
4144
4145
4145
/* Set __module__ in the dict */
4146
4146
static int
4147
- type_new_set_module (PyTypeObject * type )
4147
+ type_new_set_module (PyObject * dict )
4148
4148
{
4149
- PyObject * dict = lookup_tp_dict (type );
4150
4149
int r = PyDict_Contains (dict , & _Py_ID (__module__ ));
4151
4150
if (r < 0 ) {
4152
4151
return -1 ;
@@ -4173,10 +4172,9 @@ type_new_set_module(PyTypeObject *type)
4173
4172
/* Set ht_qualname to dict['__qualname__'] if available, else to
4174
4173
__name__. The __qualname__ accessor will look for ht_qualname. */
4175
4174
static int
4176
- type_new_set_ht_name (PyTypeObject * type )
4175
+ type_new_set_ht_name (PyTypeObject * type , PyObject * dict )
4177
4176
{
4178
4177
PyHeapTypeObject * et = (PyHeapTypeObject * )type ;
4179
- PyObject * dict = lookup_tp_dict (type );
4180
4178
PyObject * qualname ;
4181
4179
if (PyDict_GetItemRef (dict , & _Py_ID (__qualname__ ), & qualname ) < 0 ) {
4182
4180
return -1 ;
@@ -4205,9 +4203,8 @@ type_new_set_ht_name(PyTypeObject *type)
4205
4203
and is a string. The __doc__ accessor will first look for tp_doc;
4206
4204
if that fails, it will still look into __dict__. */
4207
4205
static int
4208
- type_new_set_doc (PyTypeObject * type )
4206
+ type_new_set_doc (PyTypeObject * type , PyObject * dict )
4209
4207
{
4210
- PyObject * dict = lookup_tp_dict (type );
4211
4208
PyObject * doc = PyDict_GetItemWithError (dict , & _Py_ID (__doc__ ));
4212
4209
if (doc == NULL ) {
4213
4210
if (PyErr_Occurred ()) {
@@ -4241,9 +4238,8 @@ type_new_set_doc(PyTypeObject *type)
4241
4238
4242
4239
4243
4240
static int
4244
- type_new_staticmethod (PyTypeObject * type , PyObject * attr )
4241
+ type_new_staticmethod (PyObject * dict , PyObject * attr )
4245
4242
{
4246
- PyObject * dict = lookup_tp_dict (type );
4247
4243
PyObject * func = PyDict_GetItemWithError (dict , attr );
4248
4244
if (func == NULL ) {
4249
4245
if (PyErr_Occurred ()) {
@@ -4269,9 +4265,8 @@ type_new_staticmethod(PyTypeObject *type, PyObject *attr)
4269
4265
4270
4266
4271
4267
static int
4272
- type_new_classmethod (PyTypeObject * type , PyObject * attr )
4268
+ type_new_classmethod (PyObject * dict , PyObject * attr )
4273
4269
{
4274
- PyObject * dict = lookup_tp_dict (type );
4275
4270
PyObject * func = PyDict_GetItemWithError (dict , attr );
4276
4271
if (func == NULL ) {
4277
4272
if (PyErr_Occurred ()) {
@@ -4372,9 +4367,8 @@ type_new_set_slots(const type_new_ctx *ctx, PyTypeObject *type)
4372
4367
4373
4368
/* store type in class' cell if one is supplied */
4374
4369
static int
4375
- type_new_set_classcell (PyTypeObject * type )
4370
+ type_new_set_classcell (PyTypeObject * type , PyObject * dict )
4376
4371
{
4377
- PyObject * dict = lookup_tp_dict (type );
4378
4372
PyObject * cell = PyDict_GetItemWithError (dict , & _Py_ID (__classcell__ ));
4379
4373
if (cell == NULL ) {
4380
4374
if (PyErr_Occurred ()) {
@@ -4399,9 +4393,8 @@ type_new_set_classcell(PyTypeObject *type)
4399
4393
}
4400
4394
4401
4395
static int
4402
- type_new_set_classdictcell (PyTypeObject * type )
4396
+ type_new_set_classdictcell (PyObject * dict )
4403
4397
{
4404
- PyObject * dict = lookup_tp_dict (type );
4405
4398
PyObject * cell = PyDict_GetItemWithError (dict , & _Py_ID (__classdictcell__ ));
4406
4399
if (cell == NULL ) {
4407
4400
if (PyErr_Occurred ()) {
@@ -4432,30 +4425,33 @@ type_new_set_attrs(const type_new_ctx *ctx, PyTypeObject *type)
4432
4425
return -1 ;
4433
4426
}
4434
4427
4435
- if (type_new_set_module (type ) < 0 ) {
4428
+ PyObject * dict = lookup_tp_dict (type );
4429
+ assert (dict );
4430
+
4431
+ if (type_new_set_module (dict ) < 0 ) {
4436
4432
return -1 ;
4437
4433
}
4438
4434
4439
- if (type_new_set_ht_name (type ) < 0 ) {
4435
+ if (type_new_set_ht_name (type , dict ) < 0 ) {
4440
4436
return -1 ;
4441
4437
}
4442
4438
4443
- if (type_new_set_doc (type ) < 0 ) {
4439
+ if (type_new_set_doc (type , dict ) < 0 ) {
4444
4440
return -1 ;
4445
4441
}
4446
4442
4447
4443
/* Special-case __new__: if it's a plain function,
4448
4444
make it a static function */
4449
- if (type_new_staticmethod (type , & _Py_ID (__new__ )) < 0 ) {
4445
+ if (type_new_staticmethod (dict , & _Py_ID (__new__ )) < 0 ) {
4450
4446
return -1 ;
4451
4447
}
4452
4448
4453
4449
/* Special-case __init_subclass__ and __class_getitem__:
4454
4450
if they are plain functions, make them classmethods */
4455
- if (type_new_classmethod (type , & _Py_ID (__init_subclass__ )) < 0 ) {
4451
+ if (type_new_classmethod (dict , & _Py_ID (__init_subclass__ )) < 0 ) {
4456
4452
return -1 ;
4457
4453
}
4458
- if (type_new_classmethod (type , & _Py_ID (__class_getitem__ )) < 0 ) {
4454
+ if (type_new_classmethod (dict , & _Py_ID (__class_getitem__ )) < 0 ) {
4459
4455
return -1 ;
4460
4456
}
4461
4457
@@ -4465,10 +4461,10 @@ type_new_set_attrs(const type_new_ctx *ctx, PyTypeObject *type)
4465
4461
4466
4462
type_new_set_slots (ctx , type );
4467
4463
4468
- if (type_new_set_classcell (type ) < 0 ) {
4464
+ if (type_new_set_classcell (type , dict ) < 0 ) {
4469
4465
return -1 ;
4470
4466
}
4471
- if (type_new_set_classdictcell (type ) < 0 ) {
4467
+ if (type_new_set_classdictcell (dict ) < 0 ) {
4472
4468
return -1 ;
4473
4469
}
4474
4470
return 0 ;
0 commit comments