A proposal for attribute lookup failures

MonkeeSage MonkeeSage at gmail.com
Sun Nov 18 20:04:47 EST 2007


On Nov 18, 5:59 pm, Kay Schluehr <kay.schlu... at gmx.net> wrote:

> No need to excuse. I think Ruby provides a nice context for discussing
> the semantics of top level "open classes". But I think those are
> entirely different than your contextual bindings. Note I find your
> proposal somewhat confusing since I expect that an attribute is
> "owned" by an object and is not an arbitrary contextual property.

I obviously like ruby as well as python, I just didn't want to turn
the discussion into a "I can do this in ruby, can you do that in
python" thread, so my apology was more along those lines that an
apology for using ruby at all. :)

As far as "ownership" of an object, that's what object abstraction is
all about is it not? Multiple instances can "own" a method via
polymorphic substitution, without a strict interface definition. My
proposal simply adds a new scope within which to look for "ownership".
Of course, there are problems with that, as noted above.

> Regarding open classes in Python, what about "extension classes"?
>
> class +object:
>    def len(self):
>        return self.__len__()
>
> This either adds the len method to the namespace of object or it
> creates a new namespace which is associated with the namespace of
> object s.t. each object can lookup attributes in this namespace when
> default lookup fails. I'm not entirely sure about scope. I think the
> lifetime of an extension class shall be determined by the lifetime of
> the extended class and not by the scope in which the extension class
> is defined. What do you think?

Sounds like a interesting approach! Worth looking into, imo.

> PS. you can use EasyExtend when you want to provide a language
> extension without hacking the CPython runtime. EE was made for such
> kinds of experiments.

Hadn't seen that before, thanks for the reference. :)

Regards,
Jordan



More information about the Python-list mailing list