[Pyrex] [PATCH] 'include' statements inside 'cdef class' level

Robert Bradshaw robertwb at math.washington.edu
Fri Sep 7 22:54:41 CEST 2007


On Sep 5, 2007, at 6:40 AM, Caio Marcelo wrote:

> On 9/5/07, Robert Bradshaw <robertwb at math.washington.edu> wrote:
>> from include-happy C developers). You clearly have reason in mind for
>> wanting this patch, could you please elaborate? Would being able to
>> cimport module-level cdef functions solve the problem as well?
>
> I'm working on a binding generator for a GUI toolkit (it's called
> ETK). This toolkit is built in
> C, and my generator reads C header files and output pyrex code. The
> problem is, I want to
> provide "handmaded" code for some methods. The way I imagined (and it
> seems technically
> easier to support) is tell the generator which methods to skip, and
> include a "file_over.pxi"
> where I'll put my handmade methods.
>
> Other solution would be: I could provide file_over.pxi for my
> generator and it would include
> in one resulting pxi file (like pygtk binding generator works). Or
> subclassing the classes
> generated and put the overrides there (and making sure that the "real"
> subclasses use
> the one with overrides as parent).

This second option sounds like a much better idea to me.

> I am open to suggestions, but will allowing that kind of include cause
> more harm than
> benefit? (given that technically it seems a trivial thing to do).

I see a lot of potential for abuse and for little gain (despite being  
technically trivial to implement). One thing that I really like about  
Python, and would like to maintain for Cython, is that the code is  
very readable. Allowing arbitrary includes could make things much  
harder to follow.

- Robert




More information about the Pyrex mailing list