is this a python bug?
Michael Hudson
mwh at python.net
Fri Jun 1 07:44:21 EDT 2001
paragate at gmx.net (Wolfgang Lipp) writes:
> I'm not so sure about what this is I've found. I run the code
> snippet below (Py2.1, Win95), and the Python Interpreter blows up.
Yep. Here too.
> Now, this code does have a few problems
It's certainly not the clearest code I've ever seen! Doesn't look
like it should dump core, though.
Oh, I see what's going on. I think.
The problem is that a dictionary gets mutated while it's being
printed, and thus there are pointers pointing off into never-never
land. I can reproduce this with the rather shorter:
class Child:
def __init__(self, parent):
self.__dict__['parent'] = parent
def __getattr__(self, attr):
self.parent.a = 1
self.parent.b = 1
self.parent.c = 1
return getattr(self.parent, attr)
class Parent:
def __init__(self):
self.a = Child(self)
print Parent().__dict__
I'm *almost* certain this is the same problem you're seeing. It
doesn't crash CVS Python, but I think this is more in the details than
anything; this sort of thing depends on eg. the order of items in the
dictionaries internal vector and that's changed recently.
Yep; this one crashes CVS:
class Child:
def __init__(self, parent):
self.__dict__['parent'] = parent
def __getattr__(self, attr):
self.parent.a = 1
self.parent.b = 1
self.parent.c = 1
self.parent.d = 1
self.parent.e = 1
self.parent.f = 1
self.parent.g = 1
self.parent.h = 1
self.parent.i = 1
return getattr(self.parent, attr)
class Parent:
def __init__(self):
self.a = Child(self)
print Parent().__dict__
I'll get Tim on the case <wink>.
> The code below is more or less reduced to the max. Don't fight over
> the meaningfulness of it; it's but a tiny senseless portion of the
> original.
That's as may be; but if I was up to this level of __getattr__
hackery, I'd have serious thoughts about the design of my application.
> My issue is here: Granted that the code is dumb, should it
> (or any code fed to python.exe) be able to blow up the interpreter?
No. This is (as code like yours demonstrates) surprisingly hard to
achieve, though.
Cheers,
M.
--
"declare"? my bogometer indicates that you're really programming
in some other language and trying to force Common Lisp into your
mindset. this won't work. -- Erik Naggum, comp.lang.lisp
More information about the Python-list
mailing list