Re: toOne relationship returns base class instead of subcl

John Lenton <[email protected]> Fri, 23 Jul 2004 13:48:18 -0300
Newsgroups gmane.comp.python.modeling
Message-ID <[email protected]>
On 23 Jul 2004 15:02:00 +0200, Sebastien Bigaret
<[email protected]> wrote:
> 
> 
>   Now you'll see that the discussion "ended" there with an open
>   question, about if and how this could/should be changed. Time to
>   rediscuss this I guess, huh?

ok, I've got no self-control, and I read the post. I then added the
following __getattr__ to CustomObject---I'm not at all certain this is
where it belongs, but it worked for me :) Not in production, and not
tested, but I thought I'd post it anyway

It does some magic with sys._getframe to ensure it's not called
recursively; it does it after checking the attribute doesn't start
with an underscore---which I'm not certain is ok.

  def __getattr__(self, attr):
    if attr.startswith('_'):
      raise AttributeError
    f = sys._getframe()
    if f.f_code is f.f_back.f_code:
      raise AttributeError
    print >> sys.stderr, "*** faulting object %s: %s called" % (self, attr)
    self.willRead()
    return getattr(self, attr)
    
if this is the kind of thing we're talking about, I see no problem
with it---the default behaviour is preserved due to the raising of
AttributeErrors, and it's not *too* expensive. The _getframe magick
isn't essential, but it helps.

This still didn't fix the other issue, however...

-- 
John Lenton ([email protected]) -- Random fortune:
bash: fortune: command not found


-------------------------------------------------------
This SF.Net email is sponsored by BEA Weblogic Workshop
FREE Java Enterprise J2EE developer tools!
Get your free copy of BEA WebLogic Workshop 8.1 today.
http://ads.osdn.com/?ad_id=4721&alloc_id=10040&op=click