Author arigo
Date 2005-09-02.09:40:43
SpamBayes Score
Marked as misclassified
Logged In: YES 

This is indeed a bug similar to 1202533: the infinite
recursion is in C, and doesn't go through the user-defined

The sample code snippet is definitely strange: it mixes
object.__getattribute__() with an old-style class, i.e. one
that doesn't inherit from 'object'.  This code would work as
expected if C were inheriting from 'object'.

Instead, what occurs in this crash is that the __str__ of
InstanceType calls __getattr__, which calls
object.__getattribute__(c, '__str__'); the latter returns a
so-called method wrapper object, which means essentially a
method object bound to a C function.  In this case the C
function is again the __str__ of InstanceType.  So this
__str__ ends up calling itself infinitely.

A more direct way to expose the bug is:

from types import *
class C:
    __str__ = InstanceType.__str__

Clearly, all special methods are affected:

class C:
    __add__ = InstanceType.__add__

It should be fixed together with [ 1202533 ], if the latter
is ever fixed.
Date User Action Args
2007-08-23 14:33:58adminlinkissue1267884 messages
2007-08-23 14:33:58admincreate