mirror of
https://github.com/python/cpython.git
synced 2025-07-24 11:44:31 +00:00
Fix SF bug #472234: type(obj) calls type->tp_init (Roeland Rengelink)
The fix is a band-aid: type_call() now makes the same exception for a single-argument call to type() as type_new() was already making.
This commit is contained in:
parent
b7da67a873
commit
f76de62f7d
3 changed files with 20 additions and 0 deletions
|
@ -147,6 +147,13 @@ type_call(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
|||
|
||||
obj = type->tp_new(type, args, kwds);
|
||||
if (obj != NULL) {
|
||||
/* Ugly exception: when the call was type(something),
|
||||
don't call tp_init on the result. */
|
||||
if (type == &PyType_Type &&
|
||||
PyTuple_Check(args) && PyTuple_GET_SIZE(args) == 1 &&
|
||||
(kwds == NULL ||
|
||||
(PyDict_Check(kwds) && PyDict_Size(kwds) == 0)))
|
||||
return obj;
|
||||
type = obj->ob_type;
|
||||
if (type->tp_init != NULL &&
|
||||
type->tp_init(obj, args, kwds) < 0) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue