[Python-3000] [Python-Dev] PEP 367: New Super

Tim Delaney timothy.c.delaney at gmail.com
Thu May 31 15:25:17 CEST 2007

Guido van Rossum wrote:

>> The patch notes say that you're actually inserting a keyword-only
>> argument - is this purely meant to be a stopgap measure so that
>> you've got a local (which could be put into a cell)?
> I'm not using a cell because I'm storing the result of calling
> super(Class, self) -- that is different for each instance, while a
> cell would be shared by all invocations of the same function.

I'm actually investigating another (possibly complementary) option at the 
moment - adding an im_super attribute to methods, which would store either a 
bound or unbound super instance when the bound or unbound method object is 
created. method_new becomes:

static PyObject *
method_new(PyTypeObject* type, PyObject* args, PyObject *kw)
    PyObject *func;
    PyObject *self;
    PyObject *classObj = NULL;

    if (!_PyArg_NoKeywords("instancemethod", kw))
        return NULL;
    if (!PyArg_UnpackTuple(args, "method", 2, 3,
                  &func, &self, &classObj))
        return NULL;
    if (!PyCallable_Check(func)) {
                "first argument must be callable");
        return NULL;
    if (self == Py_None)
        self = NULL;
    if (self == NULL && classObj == NULL) {
            "unbound methods must have non-NULL im_class");
        return NULL;

    return PyMethod_New(func, self, classObj);

then in method_call we could have:

static PyObject *
method_call(PyObject *func, PyObject *arg, PyObject *kw)
    PyObject *self = PyMethod_GET_SELF(func);
    PyObject *klass = PyMethod_GET_CLASS(func);
    PyObject *supervalue = PyMethod_GET_SUPER(func);

and populate the `super` argument from supervalue. I think im_super has uses 
on its own (esp. for introspection).

>> Presumably with this approach you could
>> call the method like:
>>     A().func(1, 2, super=object())
> No, because that would be a syntax error (super as a keyword is only
> allowed as an atom). You could get the same effect with
>  A().func(1, 2, **{'super': object()})
> but that's so obscure I don't mind.

I'd prefer to eliminate it, but that's a detail that can be taken care of 

Anyway, need to go to bed - have to be up in 6 hours.


Tim Delaney 

More information about the Python-3000 mailing list