# HG changeset patch # User Mike Miller # Date 1469829255 25200 # Node ID 3bdd924a5fc71110cb9127f2b17d9f753d162c4e # Parent e4175c38b0122ae3afb16dd4e9cc4ffa4b12fdd1 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. diff -r e4175c38b012 -r 3bdd924a5fc7 @py/subsref.m --- 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;