diff @pyobject/subsref.m @ 367:9d7188514f2c

Use pyobject.isa instead of lambda to check Python types * @py/subsref.m, @pyobject/methods.m, @pyobject/pyobject.m, @pyobject/subsasgn.m, @pyobject/subsref.m: Use pyobject.isa to check Python types more efficiently.
author Mike Miller <mtmiller@octave.org>
date Thu, 25 Aug 2016 15:26:32 -0700
parents 087e7bc3697f
children 4d54fb68de71
line wrap: on
line diff
--- a/@pyobject/subsref.m	Thu Aug 25 14:57:29 2016 -0700
+++ b/@pyobject/subsref.m	Thu Aug 25 15:26:32 2016 -0700
@@ -45,12 +45,9 @@
 
     case "{}"
       ## Determine the types and protocols that we are able to index into
-      x_is_mapping = pycall (pyeval (
-        "lambda x: isinstance(x, __import__('collections').Mapping)"), x);
-      x_is_sequence = pycall (pyeval (
-        ["lambda x: isinstance(x, (__import__('collections').Sequence, " ...
-                                  "__import__('array').array, " ...
-                                  "__import__('numpy').ndarray))"]), x);
+      x_is_mapping = isa (x, "py.collections.Mapping");
+      x_is_sequence = any (isa (x, {"py.collections.Sequence", ...
+                                    "py.array.array", "py.numpy.ndarray"}));
 
       if (! (x_is_mapping || x_is_sequence))
         error ("subsref: cannot index Python object, not sequence or mapping");