On Fri, 13 Feb 2004, Dan Sugalski wrote:

> We also have to have a way to fetch the method PMC for a named method
> for later use, which is where the interesting bits come in.
>
> This is required for a number of reasons, including Python, so we
> have to have it. The question is... *When* is the name resolved? That
> is, if we do:
>
>     findmethod P4, Pobject, "methodname"
>
> does the method PMC that gets stuck in P4 represent the method
> "methodname" for the object *at that point in time* or does it
> represent the method *at the time it is invoked*? That is, do we
> defer actual lookup until invocation, or do we resolve at method find
> time?


For python, you want P4 to contain the method as
it is when this op is run.

But the whole idea of a findmethod seems very
unpythonic to me. In python, a method is just another
attribute... One that happens to be callable and also
happens to know what instance it's bound to.

Consider the second line in this code:

    x = input()
    x.foo()

Is that a method call or a function call? The
compiler has no possible way of knowing, so the
second line should be compiled as if it were:

    _temp_ = getattr(x, "foo")
    _temp_()
    del _temp_

Maybe for python, findmethod and getprop (or whatever
the new eqivalent is) are the same... But I'd suspect
that getprop is all any (working) python compiler will
use.

Here are a couple examples of python weirdness:


EXAMPLE 1 - whose method is this, anyway?


    class Alice:
        def whoami(self):
            return "Alice"
    class Bruce:
        def whoami(self):
            return "Bruce"

    a = Alice()
    b = Bruce()

    a.whoami, b.whoami = b.whoami, a.whoami
    assert a.whoami()=="Bruce"
    assert b.whoami()=="Alice"

    # and just for kicks:
    freestanding = a.whoami
    assert freestanding() == "Bruce"


EXAMPLE 2 - callable classes as methods

    class Methodical:
        def __call__(self):
            return "muahahahaha"

    class Owner:
        pass

    x = Owner()
    x.method = Methodical()
    assert x.method() == "muahahahaha"


Sincerely,

Michal J Wallace
Sabren Enterprises, Inc.
-------------------------------------
contact: [EMAIL PROTECTED]
hosting: http://www.cornerhost.com/
my site: http://www.withoutane.com/
-------------------------------------

Reply via email to