Mercurial > pytave
comparison @py/subsref.m @ 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 | 9d7188514f2c |
comparison
equal
deleted
inserted
replaced
276:e4175c38b012 | 277:3bdd924a5fc7 |
---|---|
54 | 54 |
55 if (numel (idx) > 1) | 55 if (numel (idx) > 1) |
56 y = subsref (y, idx(2:end)); | 56 y = subsref (y, idx(2:end)); |
57 endif | 57 endif |
58 | 58 |
59 ## If the *last* indexing operation is ".name", and the object returned | |
60 ## is a Python callable, then call it with no arguments to be compatible | |
61 ## with how Octave functions are evaluated. | |
62 if (idx(end).type == ".") | |
63 is_callable = pyeval ("lambda x: isinstance(x, __import__('collections').Callable)"); | |
64 if (pycall (is_callable, y)) | |
65 y = pycall (y); | |
66 endif | |
67 endif | |
68 | |
59 is_none = pyeval ("lambda x: x is None"); | 69 is_none = pyeval ("lambda x: x is None"); |
60 if (nargout > 0 || ! pycall (is_none, y)) | 70 if (nargout > 0 || ! pycall (is_none, y)) |
61 varargout{1} = y; | 71 varargout{1} = y; |
62 endif | 72 endif |
63 | 73 |