8000 bpo-38211: Clean up type_init() (GH-16257) · python/cpython@ab030d6 · GitHub
[go: up one dir, main page]

Skip to content
8000

Commit ab030d6

Browse files
authored
bpo-38211: Clean up type_init() (GH-16257)
1. Remove conditions already checked by assert() 2. Remove object_init() call that effectively creates an empty tuple and checks that this tuple is empty
1 parent 0729694 commit ab030d6

File tree

1 file changed

+4
-19
lines changed

1 file changed

+4
-19
lines changed

Objects/typeobject.c

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2428,41 +2428,26 @@ valid_identifier(PyObject *s)
24282428
return 1;
24292429
}
24302430

2431-
/* Forward */
2432-
static int
2433-
object_init(PyObject *self, PyObject *args, PyObject *kwds);
2434-
24352431
static int
24362432
type_init(PyObject *cls, PyObject *args, PyObject *kwds)
24372433
{
2438-
int res;
2439-
24402434
assert(args != NULL && PyTuple_Check(args));
24412435
assert(kwds == NULL || PyDict_Check(kwds));
24422436

2443-
if (kwds != NULL && PyTuple_Check(args) && PyTuple_GET_SIZE(args) == 1 &&
2444-
PyDict_Check(kwds) && PyDict_GET_SIZE(kwds) != 0) {
2437+
if (kwds != NULL && PyTuple_GET_SIZE(args) == 1 &&
2438+
PyDict_GET_SIZE(kwds) != 0) {
24452439
PyErr_SetString(PyExc_TypeError,
24462440
"type.__init__() takes no keyword arguments");
24472441
return -1;
24482442
}
24492443

2450-
if (args != NULL && PyTuple_Check(args) &&
2451-
(PyTuple_GET_SIZE(args) != 1 && PyTuple_GET_SIZE(args) != 3)) {
2444+
if ((PyTuple_GET_SIZE(args) != 1 && PyTuple_GET_SIZE(args) != 3)) {
24522445
PyErr_SetString(PyExc_TypeError,
24532446
"type.__init__() takes 1 or 3 arguments");
24542447
return -1;
24552448
}
24562449

2457-
/* Call object.__init__(self) now. */
2458-
/* XXX Could call super(type, cls).__init__() but what's the point? */
2459-
args = PyTuple_GetSlice(args, 0, 0);
2460-
if (args == NULL) {
2461-
return -1;
2462-
}
2463-
res = object_init(cls, args, NULL);
2464-
Py_DECREF(args);
2465-
return res;
2450+
return 0;
24662451
}
24672452

24682453
unsigned long

0 commit comments

Comments
 (0)
0