comparison __py_struct_from_dict__.cc @ 373:0e4097c66788

Report a Python object's fully qualified class name correctly * oct-py-util.cc (pytave::py_object_class_name): Return the correct fully qualified class name, including module prefix. (pytave::is_py_kwargs_argument): Check for class name "__main__._OctaveKwargs". * __py_struct_from_dict__.cc (F__py_class_name__): New function. * @pyobject/methods.m (pyobject.methods): Use __py_class_name__. * @pyobject/pyobject.m (pyobject.class): Likewise.
author Mike Miller <mtmiller@octave.org>
date Fri, 26 Aug 2016 14:05:37 -0700
parents 4d54fb68de71
children d362cdd1ddeb
comparison
equal deleted inserted replaced
372:b20b8cf8ad07 373:0e4097c66788
31 #include "arrayobjectdefs.h" 31 #include "arrayobjectdefs.h"
32 #include "exceptions.h" 32 #include "exceptions.h"
33 #include "oct-py-types.h" 33 #include "oct-py-types.h"
34 #include "oct-py-util.h" 34 #include "oct-py-util.h"
35 #include "octave_to_python.h" 35 #include "octave_to_python.h"
36
37 DEFUN_DLD (__py_class_name__, args, ,
38 "-*- texinfo -*-\n\
39 @deftypefn {} {} __py_class_name__ (@var{obj})\n\
40 Return the name of the class of the Python object @var{obj}.\n\
41 \n\
42 This is a private internal function not intended for direct use.\n\
43 @end deftypefn")
44 {
45 if (args.length () != 1)
46 print_usage ();
47
48 if (! (args(0).is_object () && args(0).class_name () == "pyobject"))
49 error ("__py_class_name__: argument must be a valid Python object");
50
51 Py_Initialize ();
52
53 PyObject *obj = pytave::pyobject_unwrap_object (args(0));
54 std::string name = pytave::py_object_class_name (obj);
55 Py_DECREF (obj);
56
57 return ovl (name);
58 }
59
60 /*
61 %!assert (__py_class_name__ (pyeval ("None")), "NoneType")
62 %!assert (__py_class_name__ (pyeval ("0")), "int")
63 %!assert (__py_class_name__ (pyeval ("'Octave'")), "str")
64 %!assert (__py_class_name__ (pyeval ("[]")), "list")
65 %!assert (__py_class_name__ (pyeval ("__import__('array').array('d')")), "array.array")
66
67 %!error __py_class_name__ ()
68 %!error __py_class_name__ (1)
69 %!error __py_class_name__ (1, 2)
70 */
36 71
37 DEFUN_DLD (__py_int64_scalar_value__, args, nargout, 72 DEFUN_DLD (__py_int64_scalar_value__, args, nargout,
38 "-*- texinfo -*-\n\ 73 "-*- texinfo -*-\n\
39 @deftypefn {} {} __py_int64_scalar_value__ (@var{x})\n\ 74 @deftypefn {} {} __py_int64_scalar_value__ (@var{x})\n\
40 Extract a scalar int64 value from the Python integer @var{x}.\n\ 75 Extract a scalar int64 value from the Python integer @var{x}.\n\