[Matrix-SIG] PyArg_ParseTuple & ExtensionClasses
David Ascher
da@ski.org
Mon, 6 Sep 1999 15:44:51 -0700 (Pacific Daylight Time)
Release 12beta of NumPy makes NumPy arrays ExtensionClasses. As an
experiment, the 'base class' (written in C) is subclassed in the
Numeric.py file, which is what most users use to create arrays in Python.
Extension modules create arrays from the C modules, hence get the 'base
class'. It's been interesting seeing all the implications of moving from
a type to a class, given legacy code.
Problem: While PyArray_Check() was rewritten to do an ExtensionClass-aware
subclassing check (whereas any instance of the array type/class or of a
subclass thereof is considered an array for the purpose of the check),
there is no way to plug that check into the PyArg_ParseTuple() behavior
when the "O!" identifier is sent, along with the PyArray_Type as the
argument.
The short-term solution proposed by Travis Oliphant is to use O& and to
supply a converter function which does that checking.
A long-term solution proposed by Konrad Hinsen would be to have a new
version of PyArg_ParseTuple which accepts two new typecodes, where one
does 'isinstance' checking and the other does
'is-instance-of-a-subclass-of' checking. Off the top of my head, "O=" and
"O<" could be used for identifying those two new checks. The new function
could be called PyArg_ParseTupleEC or any other name.
The reason I'm writing you two is that 1) it's an ExtensionClass-generic
issue, and if there are other ways of doing PyArg_ParseTuple checks with
EC's, we'd love to hear about it, and 2) when Python merges types and
classes, these issues will crop up, so I thought Guido should hear about
it.
Note that O! does type equality checking and will return true for any
ExtensionClass object, not just PyArray_Type.
--david