mrkn / pycall.rb

Calling Python functions from the Ruby language
MIT License
1.06k stars 75 forks source link

[Proposal] Callable without args is regarded as a simple object (not called) #127

Closed mknkmyzk closed 3 years ago

mknkmyzk commented 4 years ago

As issue #123 pointed out, np.add.at does not work with pycall. In Python, np.add is callable, e.g. we can call np.add(a, b). However, in Python, np.add itself is an object and it is different from np.add().

On the other side, in Ruby, np.add has the same meaning as np.add(). So np.add.at equal to np.add().at, which causes this error.

My proposal is as follows: if a callable object appear without args, it is treated as a simple object in pycall.

A bad side effect of this patch is that when we call a callable object without any args, we cannot write lke 'foo' or 'foo()' but we must write like 'foo.()'.

Another side effect is that when we call a callable object with some args, we can write not only 'foo(x)' but also 'foo.(x)'.

mrkn commented 4 years ago

The notation foo.() was employed before version 1.0. But I decided to migrate the current form because Ruby is Lisp-2. So this proposal is not acceptable.

By the way, I've recognized we need a useful shorthand notation of PyCall.getattr(obj, attr). I want to add such a feature if I find a good form.

mknkmyzk commented 4 years ago

Thank you for your reply. Ignoring foo.() is a design choice, and I agree your choice.

I think this patch may be useful for someone's reference, but you can close this pull request.

Best regards.

mrkn commented 3 years ago

@mknkmyzk Thank you for your feedback.