[Pyrex] Cannot cdef __init__?
Paul Prescod
paul at prescod.net
Mon Jan 19 18:10:07 CET 2004
My opinion is that the idea of having an initializer that can accept C
types is okay but calling it __init__ is probably not. First, there are
basically no type objects in Python that are not callable from Python.
Second, you might very well want to have a constructor that is callable
from Python alongside a constructor that is only callable from C. You
could call the cdef version __cinit__. Or you could add some kind of
overloading to Pyrex in general (interesting idea...maybe you could
define cdef method XXX alongside a def method XXX and it would call the
more appropriate one based on the calling types) I'd guess you'd have to
discuss different design options on Greg's return before you'd get a
patch accepted.
But anyhow, I don't think that the workaround in this case is too
unweildy. Let's say that there are seven functions that can construct
pair objects. You define each of them like this:
cdef Pair my_init_pair_from_another_pair(pair *p1):
pair * p=init_pair_from_another_pair(p1):
rc = Pair()
Pair.p = p
cdef Pair my_init_pair_from_pairs(pair *p1, pair *2):
pair * p=init_pair_from_pairs(p1, p2):
rc = Pair()
Pair.p = p
And so forth. Basically you have one extra line of code in each of them
over this:
cdef Pair my_init_pair_from_another_pair(pair *p1):
pair * p=init_pair_from_another_pair(p1):
rc = Pair()
Pair.p = p
cdef Pair my_init_pair_from_pairs(pair *p1, pair *2):
pair * p=init_pair_from_pairs(p1, p2):
rc = Pair()
Pair.p = p
I wonder if Simon is talking about a larger issue than just this
initialization issue?
Paul Prescod
More information about the Pyrex
mailing list