# HG changeset patch # User Mike Miller # Date 1470166087 25200 # Node ID ccd9fcaae5f8bec7b5103e26502ea1e91a6a2d63 # Parent 9e8faa439d1de9ffa323e9b8d65a0b5b1acdacf4 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. diff -r 9e8faa439d1d -r ccd9fcaae5f8 @pyobject/pyobject.m --- 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")