Prothon is switching to the .NET platform

John Roth newsgroups at
Sat Aug 7 13:01:55 CEST 2004

"Peter Otten" <__peter__ at> wrote in message
news:cf1t0h$ond$03$1 at
> John Roth wrote:
> >
> > "Christopher T King" <squirrel at WPI.EDU> wrote in message
> > news:Pine.LNX.4.44.0408061533250.25906-100000 at
> >> On Fri, 6 Aug 2004, John Roth wrote:
> >>
> >> > I think it's possible to do prototypes within Python by
> >> > overriding the __getattribute__() magic method. It still
> >> > wouldn't be very pretty, but it should be able to do
> >> > everything except override the magic methods (those
> >> > seem to have to be in the class object for new style
> >> > classes).
> >>
> >
> > What I was thinking of was more along the lines of:
> >
> > class ProtoBaseClass(object):
> >     def __getattribute__(self, attr):
> >         # call object.__getattribute__(self, __dict__)
> >         # find requested attribute
> Wouldn't that part be implied if you used __getattr__() instead of
> __getattribute()?
> >         # if not found, loop through back pointer chain
> >         # if it's not a function, return the attribute
> >         # if it is a function, wrap it in a method object and return it.
> This means that an object sees all changes in its prototypes until
> explicitly assigned an attribute. Is this intentional? (real question, I'm
> not familiar with prototyped languages)

Actually, __getattribute__ sees all attribute requests, __getattr__
only sees requests where the attribute isn't found. The reason for
using __getattribute__ is that there are (I think) serious problems
with attempting to execute functions that weren't originally defined
in the base class or a subclass of the base class. In other words,
if the result is a function, there's more work that needs to be done,
and __getattr__ doesn't allow a hook to do it on the way out.

The attempt from 2000 I referred to attempted to get around this
by using a callable instance together with a lambda. Unfortunately,
it didn't work when I tried it, and as I said, after looking at the
code I don't think it ever worked. The workaround for the function
problem might work, though.


> Peter

More information about the Python-list mailing list