[Python-Dev] Strange bug only happens with Python 2.2

Gerhard Häring gerhard.haering@gmx.de
Sat, 28 Sep 2002 00:07:40 +0200

* Michael Hudson <mwh@python.net> [2002-09-27 16:39 +0100]:
> On Fri, 27 Sep 2002, Gerhard Häring wrote:
> > This is somewhat off-topic, but I'm hoping maybe someone can give a hint
> > why this only happens on Python 2.2.1.
> Guessing, but the (Jeremy's?) changes I recently backported to 
> classobject.c on the release22-maint branch might relate to this.

Maybe. I've not viewed the control flow in a debugger, but my tries to come up
with a minimalistic test case and my gut feeling says that this piece of code
has something to do with it:

static PyObject *PgLargeObject_getattr(PgLargeObject *self, char* attr)
    PyObject *res;

    res = Py_FindMethod(PgLargeObject_methods, (PyObject *)self, attr);
    if (res != NULL)
        return res;

    if (strcmp(attr, "closed") == 0)
        return Py_BuildValue("l", (long)(self->lo_fd == -1));

    if (!strcmp(attr, "__module__"))
        return Py_BuildValue("s", MODULE_NAME);

    if (!strcmp(attr, "__class__")) {
        printf("__class__ accessed!\n");
        return Py_BuildValue("s", self->ob_type->tp_name);

    return PyMember_Get((char *)self, PgLargeObject_members, attr);

from which I can see that isinstance tries to access the __class__ attribute.
Am I supposed to /not/ provide a __class__ attribute for classic types?

I haven't looked into the python22-maint changelogs yet, but I couldn't find
any related registered SF bug.

-- Gerhard