[Patches] [ python-Patches-480716 ] Support for super subclasses
noreply@sourceforge.net
noreply@sourceforge.net
Sun, 11 Nov 2001 14:12:18 -0800
Patches item #480716, was opened at 2001-11-11 14:07
You can respond by visiting:
http://sourceforge.net/tracker/?func=detail&atid=305470&aid=480716&group_id=5470
Category: Core (C code)
Group: Python 2.3
Status: Open
Resolution: None
Priority: 5
Submitted By: Greg Chapman (glchapman)
Assigned to: Nobody/Anonymous (nobody)
Summary: Support for super subclasses
Initial Comment:
In Python 2.2b1, super is subclassable, however its
__get__ (tp_descr_get) method always returns a new
instance of super (not of its actual (sub)class). I
think if super is to be subclassable, __get__ should
return a new instance of the subclass. (I've been
experimenting with using super instances to get and
set the value of inherited attributes (properties).
For this I needed a super subclass with a __setattr__
method. I also wanted to use the autosuper trick
(from test_descr.py); that's where I discovered this
behavior of __get__).
*** typeobject.c.orig Sun Nov 11 13:34:35 2001
--- typeobject.c Sun Nov 11 13:53:02 2001
***************
*** 3887,3900 ****
Py_INCREF(self);
return self;
}
! new = (superobject *)PySuper_Type.tp_new
(&PySuper_Type, NULL, NULL);
! if (new == NULL)
! return NULL;
! Py_INCREF(su->type);
! Py_INCREF(obj);
! new->type = su->type;
! new->obj = obj;
! return (PyObject *)new;
}
static int
--- 3887,3905 ----
Py_INCREF(self);
return self;
}
! if (su->ob_type != &PySuper_Type)
! /* if su is a subclass, call its type
*/
! return PyObject_CallFunction((PyObject
*)su->ob_type, "OO", su->type, obj);
! else {
! new = (superobject *)
PySuper_Type.tp_new(&PySuper_Type, NULL, NULL);
! if (new == NULL)
! return NULL;
! Py_INCREF(su->type);
! Py_INCREF(obj);
! new->type = su->type;
! new->obj = obj;
! return (PyObject *)new;
! }
}
static int
----------------------------------------------------------------------
>Comment By: Greg Chapman (glchapman)
Date: 2001-11-11 14:12
Message:
Logged In: YES
user_id=86307
I see that pasting in the patch lost all the formatting;
I've reattached it as a file. Also, I generated it using
v. 2.117 of typeobject.c.
----------------------------------------------------------------------
You can respond by visiting:
http://sourceforge.net/tracker/?func=detail&atid=305470&aid=480716&group_id=5470