On Oct 6, 2004, at 1:11 AM, Leopold Toetsch wrote:

Jeff Clites <[EMAIL PROTECTED]> wrote:

To put it another way, the expression "foo.bar()" in Python doesn't
really parse as "invoke method bar on object foo", but rather as
"lookup attribute bar on object foo

Well, there isn't much difference here. "invoke method bar" implies a method lookup that normally checks the method cache for existing (statically built) methods. If a method isn't found there, the dynamic plan B comes in. And if Python code overrides a method (attribute slot) the method cache has to be invalidated.

A few things though:

1) In my case of a = x.printMe, we need to be prepared to return a function created by currying a method using that particular instance, and for b = printWrapper.printMe we need to return a function which does type checking on its first argument (then calls the relevant method on it)--certainly doable, just odd.

2) I'd expect the method cache to be per-class, but Python can change an attribute slot on a per-instance basis (as well as a per-class basis), so we can't really use a per-class method cache (or, we need a flag on particular instances which tell us not to use it for them).

3) I won't mention the problem of languages which allow an object to have instance variables and instance methods of the same name (so that in Python, "a.b" would be ambiguous if "a" is an object from such a language).

More fun is probably to get the same inheritance ("mro") as Python.

Yes, true, and I guess related--Python must first look for things overridden on the particular instance, I think, even before looking at its class.


JEff



Reply via email to