[Spambayes] Corpus.Message.__getattr__ can't be correct can it?

Just van Rossum just at letterror.com
Fri Jan 17 22:01:30 EST 2003


Skip Montanaro wrote:

> Well, I think Richie meant it should be:
> 
>     def __getattr__(self, attributeName):
>         '''On-demand loading of the message text.'''
> 
>         if attributeName in ('hdrtxt', 'payload'):
>             self.load()
>         try:
>             return self.__dict__[attributeName]
>         except KeyError:
>             raise AttributeError, attributeName
> 
> That is, __getattr__ is called when hdrtxt or payload are accessed
> but not yet initialized.  All other accesses (or if self.load() fails
> somehow) should raise AttributeError.  See Corpus.py 1.3.

Yeah, what I wrote was nonsense. But while we're nitpicking, the _real_
intent of the code is probably this:

    def __getattr__(self, attributeName):
        '''On-demand loading of the message text.'''

        if attributeName in ('hdrtxt', 'payload'):
            self.load()
            return self.__dict__[attributeName]
        raise AttributeError, attributeName

This is assuming self.load() _always_ sets those two attrs.

Back to lurk mode...

Just



More information about the Spambayes mailing list