diff --git a/inst/@py/subsref.m b/inst/@py/subsref.m index 9316b670a9ef3a8ca853bd696adc6b7fb002a284..9e24a8cf9b43fd2bfcebb6fc456aa0558bda01ee 100644 --- a/inst/@py/subsref.m +++ b/inst/@py/subsref.m @@ -60,9 +60,17 @@ function varargout = subsref (x, idx) ## If the *last* indexing operation is ".name", and the object returned ## is a Python callable, then call it with no arguments to be compatible ## with how Octave functions are evaluated. + pyexec("import sys"); if (idx(end).type == ".") - if (isa (y, "py.collections.Callable")) - y = pycall (y); + # use hexversion of python 3.3 which introduced abc + if (double (pyeval("sys.hexversion")) >= 50528496) + if (isa (y, "py.collections.abc.Callable")) + y = pycall (y); + endif + else + if (isa (y, "py.collections.Callable")) + y = pycall (y); + endif endif endif diff --git a/inst/@pyobject/subsasgn.m b/inst/@pyobject/subsasgn.m index 7bc5e850fde9981201a9a14fcdc21493d4b8ba39..67dde470829338b624552f180dbee7b4cbfc0383 100644 --- a/inst/@pyobject/subsasgn.m +++ b/inst/@pyobject/subsasgn.m @@ -51,8 +51,13 @@ function r = subsasgn(x, idx, rhs) ## XXX: doesn't support slices or anything like that yet ## Subtract one from index: do this for lists, numpy arrays, etc - x_is_sequence = any (isa (x, {"py.collections.Sequence", ... - "py.numpy.ndarray"})); + if (double (py.sys.hexversion) >= 50528496) + x_is_sequence = any (isa (x, {"py.collections.abc.Sequence", ... + "py.numpy.ndarray"})); + else + x_is_sequence = any (isa (x, {"py.collections.Sequence", ... + "py.numpy.ndarray"})); + endif for i = 1:length (idx.subs) j = idx.subs{i}; if (x_is_sequence && isindex (j) && isnumeric (j)) diff --git a/inst/@pyobject/subsref.m b/inst/@pyobject/subsref.m index 5b5ae11798df32ef60c7c23f7610a7e5cb7f577d..7da2b9981498ff931a086ebdf85f491bbe0898f5 100644 --- a/inst/@pyobject/subsref.m +++ b/inst/@pyobject/subsref.m @@ -42,11 +42,18 @@ function varargout = subsref (x, idx) r = pycall ("getattr", x, t.subs); case "()" - ## Determine the types and protocols that we are able to index into - x_is_callable = __py_isinstance__ (x, "py.collections.Callable"); - x_is_sequence = __py_isinstance__ (x, "py.collections.Sequence") ... - | __py_isinstance__ (x, "py.array.array") ... - | __py_isinstance__ (x, "py.numpy.ndarray"); + if (double (py.sys.hexversion) > 34018032) + ## Determine the types and protocols that we are able to index into + x_is_callable = __py_isinstance__ (x, "py.collections.abc.Callable"); + x_is_sequence = __py_isinstance__ (x, "py.collections.abc.Sequence") ... + | __py_isinstance__ (x, "py.array.array") ... + | __py_isinstance__ (x, "py.numpy.ndarray"); + else + x_is_callable = __py_isinstance__ (x, "py.collections.Callable"); + x_is_sequence = __py_isinstance__ (x, "py.collections.Sequence") ... + | __py_isinstance__ (x, "py.array.array") ... + | __py_isinstance__ (x, "py.numpy.ndarray"); + endif if (! (x_is_callable || x_is_sequence)) error ("subsref: cannot index Python object, not sequence or callable"); @@ -59,11 +66,17 @@ function varargout = subsref (x, idx) r = pycall (x, t.subs{:}); case "{}" - ## Determine the types and protocols that we are able to index into x_is_mapping = __py_isinstance__ (x, "py.collections.Mapping"); - x_is_sequence = __py_isinstance__ (x, "py.collections.Sequence") ... + if (double (py.sys.hexversion) >= 50528496) + ## Determine the types and protocols that we are able to index into + x_is_sequence = __py_isinstance__ (x, "py.collections.abc.Sequence") ... | __py_isinstance__ (x, "py.array.array") ... | __py_isinstance__ (x, "py.numpy.ndarray"); + else + x_is_sequence = __py_isinstance__ (x, "py.collections.Sequence") ... + | __py_isinstance__ (x, "py.array.array") ... + | __py_isinstance__ (x, "py.numpy.ndarray"); + endif if (! (x_is_mapping || x_is_sequence)) error ("subsref: cannot index Python object, not sequence or mapping"); diff --git a/src/oct-py-eval.cc b/src/oct-py-eval.cc index b8ff922eefceb795c8795aa11c65bf9284743197..bab5c50414bc95f54be158e59086f8ba04c2a61f 100644 --- a/src/oct-py-eval.cc +++ b/src/oct-py-eval.cc @@ -84,7 +84,12 @@ namespace pythonic PyObject * py_call_function (PyObject *callable, PyObject *args, PyObject *kwargs) { +#if PY_VERSION_HEX <= 0x03080000 python_object retval = PyEval_CallObjectWithKeywords (callable, args, kwargs); +#else + python_object retval = PyObject_Call (callable, args, kwargs); +#endif + if (! retval) error_python_exception ();