[Types-sig] Re: Meta-classes discussion starter

M.-A. Lemburg mal@lemburg.com
Wed, 02 Dec 1998 17:51:31 +0100


Just van Rossum wrote:
> 
> >> +                       PyDict_DelItemString(methods, "__class__");
> 
> At 10:31 AM +0100 12/2/98, M.-A. Lemburg wrote:
> >I like the patch... but why do you delete the __class__ attribute ?
> 
> I must admit that the one aspect of the patch I am not quite confident about...
> 
> >To prevent endless recursion in some weird cases ?
> 
> No, merely from this view: while playing with the mechanism, I found myself
> constantly deleting __class__ from the dict in Python. I could not find any
> reason why I would ever need the __class__ entry.

I would just leave it there... could become useful in debugging
sessions and AFAI can see, it doesn't do any harm.
 
> [ *** warning: the author is drifting *** ed. ]
[...]
> class MyClass:
>     __class__ = MyMetaClass
>     def __init__(self, a):
>         self.a = a
> 
> class MySecondClass(MyClass):
>     def __init__(self):
>         MyClass.__init__(self, 100)
> 
> The last line can't work because
> - MyClass is in instance of MyMetaClass
> - MyClass.__init__ will be found in MyMetaClass *before* it can trigger any
> __getattr__ that could look it up inside MyClass.

That's why meta objects should have a hook that controlls *all*
getattr-actions, e.g. __meta_getattr__.

-- 
Marc-Andre Lemburg                               Y2000: 394 days left
---------------------------------------------------------------------
          : Python Pages >>> http://starship.skyport.net/~lemburg/  :
           ---------------------------------------------------------