[Pythonmac-SIG] PyObjC calling syntax again, an idea.

Ronald Oussoren oussoren@cistron.nl
Thu, 24 Oct 2002 15:57:10 +0200


On Thursday, Oct 24, 2002, at 11:35 Europe/Amsterdam, Just van Rossum 
wrote:

>
> It just occured to me that this is solvable with an appropriate 
> metaclass. This
> method:
>
>   class Foo(SomeCocoaClassWithAppropriateMetaClass):
>
>       def foo(self, arg1, arg2, arg3):
>           ...
>
> would be converted to this at class definition time:
>
>       def foo_arg1_arg2_arg3_(self, arg1, arg2, arg3):
>           ...

Automaticly converting from pretty names to ugly names, that is not 
very usefull <wink>. Meta classes are indeed a good way for this and 
PyObjC already makes use of a metaclass to control the creation of 
subclasses.

Problem is that this does not solve the calling part...

BTW. How does this work when two methods differ only in the argument 
list?

>
> Now, for the other way around (to call an ObjC from Python), maybe a 
> similar
> trick can be used? If it is possible to query a class at runtime which 
> selectors
> it supports, maybe Python wrappers can be generated on the fly so you 
> can still
> do
>
>   obj.foo(arg1="x", arg2="y")

Problem is that keyword arguments, which you'd have to use to even see 
the argument names used by the caller, are implemented using python 
dicts. This means you loose the order of arguments, and the order is 
important here! It is quite conceivable that their exist two 
Objective-C selectors that differ only in the order of the name 
fragments.

Ronald