[Pyrex] Why were .pxd files invented?

Greg Ewing greg.ewing at canterbury.ac.nz
Tue Apr 3 05:41:22 UTC 2007


Leif Strand wrote:
> Even if you decide to keep separate, manually-edited .pxd files, 
> you still might want -Mx options to generate the Makefile 
> interdependencies between Pyrex modules automatically (based upon the 
> 'cinclude' statements).

Yes, that would certainly be a good idea, and not difficult
to do.

> With generated .pxd files, you could still clearly separate interface & 
> implementation, but do it syntactically inside the .pyx file, similar to 
> a Pascal module

I'm not sure what the advantage of that would be. There
would still be two places to edit if you want to add or
change a C method.

>    cinterface:  # from this the .pxd would be generated
>        cdef int width
>        cdef int length
> 
>        cdef trim(self):
>            self.width = self.width - 1

But you're mixing interface and implementation here.
Only the header of the method is part of the interface.

> One advantage of this is that a class could have 'private' cdef methods 
> (declared outside the 'cinterface' block).

Not really -- if the method is to be overridable, it
has to go in the vtable, and the vtable layout is part
of the interface.

I might be able to overcome that by having another
vtable for private C methods hanging off the main one.
But that's independent of the pxd/pyx issue.

> What bugs me is having to toggle between two separate files while 
> editing a class,

I suppose that just doesn't bug me as much -- editing
two files or editing two places in one file doesn't
seem much different to me. If anything, two files is
easier, because I can display them side by side more
easily.

 > If I want to add
> an argument to the 'trim' method, I should be able to make the change in 
> once place!

I understand what you're saying, but that doesn't
seem to be possible while also keeping interface and
implementation syntactically separated.

--
Greg



More information about the Pyrex mailing list