Maybe this will work?

client.on_connect = PyCall.jlfun2pyfun(on_connect)
client.on_message = PyCall.jlfun2pyfun(on_message)

jlfun2pyfun simply inserts an extra level of indirection through a native 
Python lambda, which does have a func_code.


On Wednesday, April 27, 2016 at 7:51:06 PM UTC-4, Steven G. Johnson wrote:
>
>
>
> On Wednesday, April 27, 2016 at 7:06:46 PM UTC-4, Kaj Wiik wrote:
>>
>>
>> OK, I see, thanks. I found this from the module source (client.py):
>>             if sys.version_info[0] < 3:
>>                 argcount = self.on_connect.func_code.co_argcount
>>             else:
>>                 argcount = self.on_connect.__code__.co_argcount
>>
>>
> It might be possible to provide this.   The PyCall function wrapper could 
> add a func_code (or __code__ in Py3) attribute that returns an object with 
> at least some of the attributes of the Python func_code, e.g. co_argcount 
> (the number of arguments), co_filename (the file where it is defined), 
> co_firstlineno (the line number), co_name (the name of the function).
>
> An inherent difficulty is that Julia functions can have multiple methods 
> with different argument counts (and defined in different files etcetera), 
> but I guess we could look at methods(f) to see if all of the methods have 
> the same number of arguments, or return the maximum number of arguments or 
> something.
>
> (PyCall PRs welcome, of course.)
>

Reply via email to