Pb with __del__ and inheritence

E

Erwan Adam

Hello all,

Can someone reproduce this bug ... I use :

[adam@is111902 /home/adam/Work/Python]> python
Python 2.4.3 (#2, Sep 18 2006, 21:07:35)
[GCC 4.1.1 20060724 (prerelease) (4.1.1-3mdk)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
First test :

[adam@is111902 /home/adam/Work/Python]> cat bug_del.py && echo "------"
&& python bug_del.py

class XObject(object):

def __del__(self):
print "XObject.__del__"
return

pass

class A(XObject):

def __del__(self):
print "A.__del__"
XObject.__del__(self)
return

pass

a = A()
------
A.__del__
XObject.__del__
[adam@is111902 /home/adam/Work/Python]>

Everything is ok ... now I just replace "a = A()" by "aaa = A()":

[adam@is111902 /home/adam/Work/Python]> cat bug_del.py && echo "------"
&& python bug_del.py

class XObject(object):

def __del__(self):
print "XObject.__del__"
return

pass

class A(XObject):

def __del__(self):
print "A.__del__"
XObject.__del__(self)
return

pass

aaa = A()
------
A.__del__
Exception exceptions.AttributeError: "'NoneType' object has no attribute
'__del__'" in <bound method A.__del__ of <__main__.A object at
0xb7bb124c>> ignored
[adam@is111902 /home/adam/Work/Python]>

!!!


Thanks in advance,

E.A.
 
G

Gabriel Genellina

Can someone reproduce this bug ... I use :
Same on 2.5 Windows.
class XObject(object):

def __del__(self):
print "XObject.__del__"
return

pass

class A(XObject):

def __del__(self):
print "A.__del__"
XObject.__del__(self)
return

pass

aaa = A()
------
A.__del__
Exception exceptions.AttributeError: "'NoneType' object has no attribute
'__del__'" in <bound method A.__del__ of <__main__.A object at
0xb7bb124c>> ignored

Print XObject inside A.__del__ and you can see that it is None. That means
that the XObject reference was set to None *before* aaa was deleted.
Values inside the module namespace are set to None when it's destroyed (to
break possible reference cycles, I presume). I can't find any place in the
docs that guarantees any ordering on the object deletion, so I don't
consider this a "bug". See the big notes on the __del__ method docs.

If you *really* must do some cleanup on A.__del__, you can't trust on
*any* globals, and you must store a reference to anything needed inside
__del__
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,981
Messages
2,570,187
Members
46,730
Latest member
AudryNolan

Latest Threads

Top