# HG changeset patch # User Mike Miller # Date 1472162249 25200 # Node ID 5c900b8383c41ec946c1709a00ccefd61015f721 # Parent 087e7bc3697fc1f084f098bcd4c2f651988b54e4 pyobject.isa: work with a cell array of type names * @pyobject/pyobject.m (pyobject.isa): Accept a cell array of type names for compatibility with Octave's default isa function. diff -r 087e7bc3697f -r 5c900b8383c4 @pyobject/pyobject.m --- a/@pyobject/pyobject.m Thu Aug 25 14:06:56 2016 -0700 +++ b/@pyobject/pyobject.m Thu Aug 25 14:57:29 2016 -0700 @@ -119,12 +119,21 @@ function y = isa (x, typestr) assert (nargin == 2); - assert (ischar (typestr)); - if ((numel (typestr) > 3) && (typestr(1:3) == "py.")) - y = __py_isinstance__ (x, typestr); - else - y = builtin ("isa", x, typestr); + assert (ischar (typestr) || iscellstr (typestr)); + + if (ischar (typestr)) + typestr = { typestr }; endif + + y = false (size (typestr)); + + for i = 1:numel (typestr) + if ((numel (typestr{i}) > 3) && (typestr{i}(1:3) == "py.")) + y(i) = __py_isinstance__ (x, typestr{i}); + else + y(i) = builtin ("isa", x, typestr{i}); + endif + endfor endfunction function y = struct (x) @@ -346,6 +355,7 @@ %!assert (isa (pyobject (struct ()), "py.dict")) %!assert (isa (pyobject (cell ()), "py.tuple")) %!assert (isa (pyobject ([1, 2, 3, 4]), "py.array.array")) +%!assert (all (isa (pyobject (0), {"pyobject", "py.float", "py.numbers.Number"}))) ## Test conversion method pyobject.int64 %!assert (int64 (pyobject (int8 (0))), int64 (0))