[Cython] [cython-users] Cython .pxd introspection: listing defined constants

Greg Ewing greg.ewing at canterbury.ac.nz
Sun Feb 20 22:09:42 CET 2011


W. Trevor King wrote:
> On Sat, Feb 19, 2011 at 04:41:27PM -0800, Robert Bradshaw wrote:
> 
>>On Sat, Feb 19, 2011 at 3:31 PM, W. Trevor King <wking at drexel.edu> wrote:
>>
>>>   cython $ grep class Cython/Includes/numpy.pxd
>>>       ctypedef class numpy.dtype [object PyArray_Descr]:
>>>       ctypedef extern class numpy.flatiter [object PyArrayIterObject]:
>>>       ctypedef extern class numpy.broadcast [object PyArrayMultiIterObject]:
>>>       ctypedef class numpy.ndarray [object PyArrayObject]:
>>>       ctypedef extern class numpy.ufunc [object PyUFuncObject]:
>>
>>"numpy.dtype" is the fully qualified name of the class it's
>>declaring--the module is "numpy."

Aren't the module names in the class declarations redundant here?
Since they're in a file called numpy.pxd, declarations will go into
the numpy module namespace by default. You should be able to write
these as just

   ctypedef class dtype [object PyArray_Descr]:
   ctypedef class flatiter [object PyArrayIterObject]:
   ctypedef class broadcast [object PyArrayMultiIterObject]:
   ctypedef class ndarray [object PyArrayObject]:
   ctypedef class ufunc [object PyUFuncObject]:

The 'extern' syntax for extension classes, including a module name,
is really an obsolete feature. Before Pyrex had .pxd files, it was
the only way to declare an externally implemented extension type
to Pyrex. But now that .pxd files exist, there should be no need
for it.

> Hmm, that means that
> 
>     cimport numpy
>     a = numpy.numpy.ndarray
> 
> also compiles.

Compiles and runs, or just compiles? If this works as a way of
getting hold of the ndarray type, then it's a bug -- it's not
supposed to work that way.

-- 
Greg


More information about the cython-devel mailing list