changeset 284:6c133bcac33a

use pyobject instead of accessing the InOct dict * @pyobject/fieldnames.m: Use our tools. * @pyobject/methods.m: Use our tools. * @pyobject/pyobject.m (@pyobject/whatclass): Use our tools.
author Colin Macdonald <cbm@m.fsf.org>
date Tue, 02 Aug 2016 00:03:51 -0700
parents 3bf799e80ca5
children 06a4b461b141
files @pyobject/fieldnames.m @pyobject/methods.m @pyobject/pyobject.m
diffstat 3 files changed, 10 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/@pyobject/fieldnames.m	Fri Jul 29 20:15:39 2016 -0700
+++ b/@pyobject/fieldnames.m	Tue Aug 02 00:03:51 2016 -0700
@@ -47,14 +47,13 @@
 
 function names = fieldnames (x)
 
-  cmd = sprintf (["[a for x in (__InOct__['%s'],) for a in dir(x) " ...
-                  " if not callable(getattr(x, a))" ...
-                  " and not isinstance(getattr(x, a), __import__('types').ModuleType)" ...
-                  " and not a.startswith('_')]"],
-                 getid (x));
+  cmd = pyeval (["lambda x: [a for a in dir(x)" ...
+                 " if not callable(getattr(x, a))" ...
+                 " and not isinstance(getattr(x, a), __import__('types').ModuleType)" ...
+                 " and not a.startswith('_')]"]);
 
   # FIXME: may need to convert from Python list to Octave cell array
-  names = pyeval (cmd);
+  names = pycall (cmd, x);
   names = names(:);
 
 endfunction
--- a/@pyobject/methods.m	Fri Jul 29 20:15:39 2016 -0700
+++ b/@pyobject/methods.m	Tue Aug 02 00:03:51 2016 -0700
@@ -68,13 +68,11 @@
 function mtds = methods (x)
 
   # filter the output of `dir(x)` to get callable methods only
-  cmd = sprintf (["[a for x in (__InOct__['%s'],) for a in dir(x) " ...
-                  " if callable(getattr(x, a))" ...
-                  " and not a.startswith('__')]"],
-                 getid (x));
+  cmd = pyeval (["lambda x: [a for a in dir(x)" ...
+                 " if callable(getattr(x, a)) and not a.startswith('__')]"]);
 
   # FIXME: may need to convert from Python list to Octave cell array
-  mtds_list = pyeval (cmd);
+  mtds_list = pycall (cmd, x)
 
   if (nargout == 0)
     ## FIXME: should this be available as @pyobject/ismodule.m ?
--- a/@pyobject/pyobject.m	Fri Jul 29 20:15:39 2016 -0700
+++ b/@pyobject/pyobject.m	Tue Aug 02 00:03:51 2016 -0700
@@ -110,7 +110,8 @@
     endfunction
 
     function s = whatclass (x)
-      s = pyeval (sprintf ("str(__InOct__['%s'].__class__)", x.id));
+      idx = struct ("type", ".", "subs", "__class__");
+      s = subsref (x, idx);
     endfunction
 
     function vargout = help (x)