On Tue Jul 07 15:42:47 2009, NINE wrote:
Show quoted text> On Fri Jun 19 18:42:28 2009,
>
https://www.google.com/accounts/o8/id?id=AItOawlexYTVVJ0Oz98YNS01DA5avM0engOM7NU
Show quoted text> wrote:
> > When obj is a pointer to a method or function, Py2Pl returns its
> string
> > representation, rather than the wrapped method/function.
> >
> > On line 48 of py2pl.c, it does a diagnostic check to see if obj is a
> > method, but that is the only occurrence of the words "method" or
> > "function" in the entire file.
> >
> > There should be blocks for "if (PyMethod_Check(obj))" and "if
> > (PyFunction_Check(obj))" that return a PyMethod or PyFunction object
> > respectively.
>
> The freshly uploaded Inline::Python 0.29 does a PyFunction_Check and
> supports exporting lambda expressions and function references from
> Python
> to Perl space as Inline::Python::Function objects which are callable.
>
> Does this work for you, so I can close this bug?
First of all, thanks a lot for the quick turnaround on this. This
package is great, and this additional implementation will make it even
better!
Unfortunately, however, I believe (but have yet to verify) that this
will only half-fix the problem. I don't know if perl represents
subroutines that are bound to objects differently in the background, but
python definitely does. It will probably also require a PyMethod_Check
call since python doesn't consider a method to be the same as a
function. A python method is an object that contains a class, a function
and an instance:
Show quoted text>>> import inspect
>>> class MyClass(object):
... def Method(self):
... pass
...
Show quoted text>>> def Function():
... pass
...
Show quoted text>>> inspect.ismethod(MyClass.Method)
True
Show quoted text>>> inspect.isfunction(MyClass.Method)
False
Show quoted text>>> inspect.ismethod(Function)
False
Show quoted text>>> inspect.isfunction(Function)
True
Show quoted text>>> dir(MyClass.Method)
['__call__', '__class__', '__cmp__', '__delattr__', '__doc__',
'__get__', '__getattribute__', '__hash__', '__init__', '__new__',
'__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__str__',
'im_class', 'im_func', 'im_self']
Show quoted text>>> MyClass.Method.im_self
>>> MyClass.Method.im_class
<class '__main__.MyClass'>
Show quoted text>>> instance = MyClass()
>>> instance.Method.im_self
<__main__.MyClass object at 0xb7ef1fac>