Mercurial > pytave
changeset 277:3bdd924a5fc7
py: call function or object with no arguments to be consistent with Octave
* @py/subsref.m: If the returned Python object is callable and no argument
list is given, call it with no arguments.
author | Mike Miller <mtmiller@octave.org> |
---|---|
date | Fri, 29 Jul 2016 14:54:15 -0700 |
parents | e4175c38b012 |
children | 6e83efbcf1bc |
files | @py/subsref.m |
diffstat | 1 files changed, 10 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/@py/subsref.m Fri Jul 29 14:51:24 2016 -0700 +++ b/@py/subsref.m Fri Jul 29 14:54:15 2016 -0700 @@ -56,6 +56,16 @@ y = subsref (y, idx(2:end)); endif + ## If the *last* indexing operation is ".name", and the object returned + ## is a Python callable, then call it with no arguments to be compatible + ## with how Octave functions are evaluated. + if (idx(end).type == ".") + is_callable = pyeval ("lambda x: isinstance(x, __import__('collections').Callable)"); + if (pycall (is_callable, y)) + y = pycall (y); + endif + endif + is_none = pyeval ("lambda x: x is None"); if (nargout > 0 || ! pycall (is_none, y)) varargout{1} = y;