Mercurial > pytave
changeset 287:ccd9fcaae5f8
pyobject: rename "whatclass" to "class", make Matlab compatible
* @pyobject/pyobject.m (class): Rename from "whatclass". Return the string
name of the object's type, with "py" namespace prefix. Add tests.
author | Mike Miller <mtmiller@octave.org> |
---|---|
date | Tue, 02 Aug 2016 12:28:07 -0700 |
parents | 9e8faa439d1d |
children | a0dc81daf553 |
files | @pyobject/pyobject.m |
diffstat | 1 files changed, 12 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/@pyobject/pyobject.m Tue Aug 02 12:11:02 2016 -0700 +++ b/@pyobject/pyobject.m Tue Aug 02 12:28:07 2016 -0700 @@ -145,9 +145,12 @@ endif endfunction - function s = whatclass (x) + function s = class (x) idx = struct ("type", ".", "subs", "__class__"); - s = subsref (x, idx); + class_ref = subsref (x, idx); + idx = struct ("type", ".", "subs", "__name__"); + s = subsref (class_ref, idx); + s = sprintf ("py.%s", char (s)); endfunction function vargout = help (x) @@ -197,3 +200,10 @@ %!assert (isa (pyobject (42.2), "pyobject")) %!assert (isa (pyobject (int32 (42)), "pyobject")) %!assert (isa (pyobject (pyobject ()), "pyobject")) + +%!assert (class (pyeval ("{}")), "py.dict") +%!assert (class (pyeval ("[]")), "py.list") +%!assert (class (pyeval ("()")), "py.tuple") +%!assert (class (pyeval ("set()")), "py.set") +%!assert (class (pyeval ("None")), "py.NoneType") +%!assert (class (pyeval ("2.5")), "double")