Joel Uckelman on Thu, 9 Dec 2004 16:46:23 -0600 (CST)


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: [nimh-dev] virtual member functions


Thus spake Joel Uckelman:
> 
> What I have is this:
> 
> class Base:
>   def foo(self):
>     print "bar"
> 
>   def frobnicate(self):
>     self.foo()
>  
> class Derived(Base):
>   def foo(self):
>     print "baz"
>  
> x = Derived()
> x.frobnicate() # want to print baz
> 
> Here, I'm not directly calling the overridden function; instead, a 
> non-overridden function from the base class is. This example code works. 
> What doesn't work is doing this with nimh.Folder.parsesequence(). Try 
> feeding scan.py a sequence which generates an error message, and the last 
> line of the stack trace will be something like this:
> 
>   File "/usr/lib/python2.3/mhlib.py", line 365, in parsesequence
>     raise Error, "bad message list %s" % seq
> 
> If nimh.Folder.parsesequence() were being called, then the one in mhlib.py 
> wouldn't be called at all, so something has gone wrong here.

I figured out what the surface problem was: nimh_nimh had no openfolder() of its own. The importance of that is that mhlib.MH.openfolder() returns mhlib.Folders rather than our nimh_folders, and nimh_folder is where parsesequence() lives. So, I went through mhlib to find all of the functions which return classes which we've subclassed and overrode all of those functions in the subclasses.

This revealed another problem, one for which I haven't been able to decipher the stack trace:

[uckelman@scylla bin]$ ./scan.py
Traceback (most recent call last):
  File "./scan.py", line 41, in ?
    if 'Subject' in msg: short_subject = msg['Subject'][0:40]
  File "/usr/src/build/475206-i386/install/usr/lib/python2.3/email/Message.py", line 327, in __contains__
AttributeError: nimh_message instance has no attribute '_headers'

Yeah. So the problem claims to be in a file which was part of the _build_ for Python, and doesn't even exist on my system.

When I change the second line of message.py to 'import email.Message', and the base class in the constructor to 'email.Message', I get the following:

  File "/home/uckelman/projects/nimh/trunk/lib/nimh/Message.py", line 4, in ?
    class Message(email.Message):
TypeError: function takes at most 2 arguments (3 given)

I don't see how I'm giving 3 arguments here. I think I'm giving 1.

-- 
J.


_______________________________________________
nimh-dev mailing list
nimh-dev@xxxxxxxxxxx
http://lists.ellipsis.cx/mailman/listinfo/nimh-dev