Skip to content

Commit b6fafa9

Browse files
Revert "Preget tp_dict"
This reverts commit 1eed75d.
1 parent a792e9d commit b6fafa9

1 file changed

Lines changed: 22 additions & 18 deletions

File tree

Objects/typeobject.c

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4144,8 +4144,9 @@ type_new_set_name(const type_new_ctx *ctx, PyTypeObject *type)
41444144

41454145
/* Set __module__ in the dict */
41464146
static int
4147-
type_new_set_module(PyObject *dict)
4147+
type_new_set_module(PyTypeObject *type)
41484148
{
4149+
PyObject *dict = lookup_tp_dict(type);
41494150
int r = PyDict_Contains(dict, &_Py_ID(__module__));
41504151
if (r < 0) {
41514152
return -1;
@@ -4172,9 +4173,10 @@ type_new_set_module(PyObject *dict)
41724173
/* Set ht_qualname to dict['__qualname__'] if available, else to
41734174
__name__. The __qualname__ accessor will look for ht_qualname. */
41744175
static int
4175-
type_new_set_ht_name(PyTypeObject *type, PyObject *dict)
4176+
type_new_set_ht_name(PyTypeObject *type)
41764177
{
41774178
PyHeapTypeObject *et = (PyHeapTypeObject *)type;
4179+
PyObject *dict = lookup_tp_dict(type);
41784180
PyObject *qualname;
41794181
if (PyDict_GetItemRef(dict, &_Py_ID(__qualname__), &qualname) < 0) {
41804182
return -1;
@@ -4203,8 +4205,9 @@ type_new_set_ht_name(PyTypeObject *type, PyObject *dict)
42034205
and is a string. The __doc__ accessor will first look for tp_doc;
42044206
if that fails, it will still look into __dict__. */
42054207
static int
4206-
type_new_set_doc(PyTypeObject *type, PyObject* dict)
4208+
type_new_set_doc(PyTypeObject *type)
42074209
{
4210+
PyObject *dict = lookup_tp_dict(type);
42084211
PyObject *doc = PyDict_GetItemWithError(dict, &_Py_ID(__doc__));
42094212
if (doc == NULL) {
42104213
if (PyErr_Occurred()) {
@@ -4238,8 +4241,9 @@ type_new_set_doc(PyTypeObject *type, PyObject* dict)
42384241

42394242

42404243
static int
4241-
type_new_staticmethod(PyObject *dict, PyObject *attr)
4244+
type_new_staticmethod(PyTypeObject *type, PyObject *attr)
42424245
{
4246+
PyObject *dict = lookup_tp_dict(type);
42434247
PyObject *func = PyDict_GetItemWithError(dict, attr);
42444248
if (func == NULL) {
42454249
if (PyErr_Occurred()) {
@@ -4265,8 +4269,9 @@ type_new_staticmethod(PyObject *dict, PyObject *attr)
42654269

42664270

42674271
static int
4268-
type_new_classmethod(PyObject *dict, PyObject *attr)
4272+
type_new_classmethod(PyTypeObject *type, PyObject *attr)
42694273
{
4274+
PyObject *dict = lookup_tp_dict(type);
42704275
PyObject *func = PyDict_GetItemWithError(dict, attr);
42714276
if (func == NULL) {
42724277
if (PyErr_Occurred()) {
@@ -4367,8 +4372,9 @@ type_new_set_slots(const type_new_ctx *ctx, PyTypeObject *type)
43674372

43684373
/* store type in class' cell if one is supplied */
43694374
static int
4370-
type_new_set_classcell(PyTypeObject *type, PyObject *dict)
4375+
type_new_set_classcell(PyTypeObject *type)
43714376
{
4377+
PyObject *dict = lookup_tp_dict(type);
43724378
PyObject *cell = PyDict_GetItemWithError(dict, &_Py_ID(__classcell__));
43734379
if (cell == NULL) {
43744380
if (PyErr_Occurred()) {
@@ -4393,8 +4399,9 @@ type_new_set_classcell(PyTypeObject *type, PyObject *dict)
43934399
}
43944400

43954401
static int
4396-
type_new_set_classdictcell(PyObject *dict)
4402+
type_new_set_classdictcell(PyTypeObject *type)
43974403
{
4404+
PyObject *dict = lookup_tp_dict(type);
43984405
PyObject *cell = PyDict_GetItemWithError(dict, &_Py_ID(__classdictcell__));
43994406
if (cell == NULL) {
44004407
if (PyErr_Occurred()) {
@@ -4425,33 +4432,30 @@ type_new_set_attrs(const type_new_ctx *ctx, PyTypeObject *type)
44254432
return -1;
44264433
}
44274434

4428-
PyObject *dict = lookup_tp_dict(type);
4429-
assert(dict);
4430-
4431-
if (type_new_set_module(dict) < 0) {
4435+
if (type_new_set_module(type) < 0) {
44324436
return -1;
44334437
}
44344438

4435-
if (type_new_set_ht_name(type, dict) < 0) {
4439+
if (type_new_set_ht_name(type) < 0) {
44364440
return -1;
44374441
}
44384442

4439-
if (type_new_set_doc(type, dict) < 0) {
4443+
if (type_new_set_doc(type) < 0) {
44404444
return -1;
44414445
}
44424446

44434447
/* Special-case __new__: if it's a plain function,
44444448
make it a static function */
4445-
if (type_new_staticmethod(dict, &_Py_ID(__new__)) < 0) {
4449+
if (type_new_staticmethod(type, &_Py_ID(__new__)) < 0) {
44464450
return -1;
44474451
}
44484452

44494453
/* Special-case __init_subclass__ and __class_getitem__:
44504454
if they are plain functions, make them classmethods */
4451-
if (type_new_classmethod(dict, &_Py_ID(__init_subclass__)) < 0) {
4455+
if (type_new_classmethod(type, &_Py_ID(__init_subclass__)) < 0) {
44524456
return -1;
44534457
}
4454-
if (type_new_classmethod(dict, &_Py_ID(__class_getitem__)) < 0) {
4458+
if (type_new_classmethod(type, &_Py_ID(__class_getitem__)) < 0) {
44554459
return -1;
44564460
}
44574461

@@ -4461,10 +4465,10 @@ type_new_set_attrs(const type_new_ctx *ctx, PyTypeObject *type)
44614465

44624466
type_new_set_slots(ctx, type);
44634467

4464-
if (type_new_set_classcell(type, dict) < 0) {
4468+
if (type_new_set_classcell(type) < 0) {
44654469
return -1;
44664470
}
4467-
if (type_new_set_classdictcell(dict) < 0) {
4471+
if (type_new_set_classdictcell(type) < 0) {
44684472
return -1;
44694473
}
44704474
return 0;

0 commit comments

Comments
 (0)