[Types-sig] method binding
Edward Welbourne
Edward Welbourne <eddyw@lsl.co.uk>
Tue, 8 Dec 1998 19:06:25 GMT
> 2. Objects can delegate attribute fetching to __bases__ objects in almost
> the same way current classes do, except that the fetched attribute is not
> processed or hooked in any way (eg. you get raw functions instead of
> methods).
No `except ...' clause. Not `almost': exactly.
class A:
def fred(self): pass
class B(A): pass
B.fred isn't processed or hooked in any way, it just used the B->A bases
link. It is exactly the same entity as A.fred. It is not
lambda *args: apply(A.fred, (B,) + args)
By contrest, after
b = B()
b.fred is munged, but that's because the lookup went via the b->B class link.
> 3. Objects can also delegate attribute fetching to __classes__ objects, or
> more specifically, to their __getinstattr__ functions.
That specific is important. It would probably make sense to replace the
__classes__ list I involved with the list of __getinstattr__ callables.
Of course, these could be bound methods (enabling them to access the
namespace of whoever they're bound to, typically what we used to think
of as a class).
> This, on the other hand, would break everything.
;^>
> How do you spell something which acts like classes do now?
Just the way we do at present, I'd reckon.
> How do you obtain an 'instance' from this 'class'?
sorry, I missed part of the definition of
class Class:
# stuff from before ignored
def __call__(self, *args):
# need builtin newobject function of course
result = newobject()
# result.__fetchers__ = (self.__getinstattr__,)
result.__classes__ = (self,)
try: meth = getattr(self, '__init__')
except AttributeError: pass
else: apply(meth, (result,) + args)
return result
Anything subclassed from that base will then behave just like the sorts
of classes we're used to. I imagine.
> How do you choose to treat an object as a class when handling it
> directly (not through delegation from an 'instance')?
I haven't understood this question.
So the following may be off topic.
`to treat an object as a class' is simply to have it in one's __classes__
list: there is no other sense in which one treats anything as a class.
> I'm confused, but interested.
Oh good: I've done something useful today ;^>
Eddy.