[Python-Dev] CALL_ATTR, A Method Proposal

Finn Bock bckfnn@worldonline.dk
Mon, 17 Feb 2003 09:04:14 +0100


[Guido van Rossum]

 > Here's how I think the CALL_ATTR opcode should work:

Which is basicly what Jython does (except that jython does
not yet have new-style classes).

Jython also does a tiny bit of handling of non-functions.
Maybe that is usefull here too.

  >     if <obj> is a new instance:
  >        if the class's getattr policy is standard:
  >           if <name> not in <obj>.__dict__:
  >              search <obj>.__class__ and its base classes for <name>
  >              if found and the result is a Python function:
  >                  call it with arguments (<obj>, <args>) and return
  >     elif <obj> is a classic instance:
  >        if <name> not in <obj>.__dict__:
  >           search <obj>.__class__ and its base classes for <name>
  >           if found:
                   if the result is a Python function:
                       call it with arguments (<obj>, <args>) and return
                   else:
                       bind the non-function and call with (<args>)
  >     # if we get here, the optimization doesn't apply
  >     tmp = getattr(<obj>, <name>)
  >     return tmp(<args>)

regards,
finn