[Patches] [ python-Patches-480716 ] Support for super subclasses

noreply@sourceforge.net noreply@sourceforge.net
Sun, 11 Nov 2001 14:07:25 -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


----------------------------------------------------------------------

You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=305470&aid=480716&group_id=5470