[ python-Bugs-1267884 ] crash recursive __getattr__
SourceForge.net
noreply at sourceforge.net
Fri Sep 2 11:40:44 CEST 2005
Bugs item #1267884, was opened at 2005-08-24 10:22
Message generated for change (Comment added) made by arigo
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1267884&group_id=5470
Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Python Interpreter Core
Group: Python 2.4
Status: Closed
Resolution: Duplicate
Priority: 5
Submitted By: pinzo (rodrigo_rc)
Assigned to: Nobody/Anonymous (nobody)
Summary: crash recursive __getattr__
Initial Comment:
The following code eats all stack space and crashes,
both in Windows and Linux:
------------8<-------------
class C:
def __getattr__(self, a):
return object.__getattribute__(self, a)
c = C()
str(c)
------------8<-------------
It shoud probably raise "RuntimeError: maximum
recursion depth exceeded" or similar instead.
----------------------------------------------------------------------
>Comment By: Armin Rigo (arigo)
Date: 2005-09-02 09:40
Message:
Logged In: YES
user_id=4771
This is indeed a bug similar to 1202533: the infinite
recursion is in C, and doesn't go through the user-defined
__getattr__().
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__
str(C())
Clearly, all special methods are affected:
class C:
__add__ = InstanceType.__add__
C()+1
It should be fixed together with [ 1202533 ], if the latter
is ever fixed.
----------------------------------------------------------------------
Comment By: Terry J. Reedy (tjreedy)
Date: 2005-09-01 20:37
Message:
Logged In: YES
user_id=593130
I believe this is essentially the same as open bug
[ 1202533 ] a bunch of infinite C recursions
Closing as duplicate and adding a cross-reference note to
1202533. Reopen if a fix to the above, if and when there is one,
does not fix this.
----------------------------------------------------------------------
Comment By: Terry J. Reedy (tjreedy)
Date: 2005-09-01 20:35
Message:
Logged In: YES
user_id=593130
I believe this is essentially the same as open bug
[ 1202533 ] a bunch of infinite C recursions
Closing as duplicate and adding note to 1202533. Reopen if a
fix to the above, if and when there is one, does not fix this.
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1267884&group_id=5470
More information about the Python-bugs-list
mailing list