Re: [Cython] [Pyrex] exposing extension class attributes

Robert Bradshaw <[email protected]>
Newsgroups gmane.comp.python.cython.devel,gmane.comp.python.pyrex
Message-ID <[email protected]>
On Mar 18, 2008, at 5:04 PM, Greg Ewing wrote:

> Simon Burton wrote:
>> Ie. the c attribute has an underscore in front of it, and
>> from python the attribute is without underscore.
>>
>> As this is likely to drive me moderately crazy (keeping track
>> of underscores) I am wondering how other people handle this issue ?
>
> Would calling it "c_foo" make you feel any better?
>
> I'm not sure what could be done to make this any easier,
> short of having some magic by which the same name refers
> to the C attribute in Pyrex and the Python property in
> Python. But you need to be able to refer to the property
> in Pyrex as well, so I can't see how that would work.
>
>> A similar problem occurs with methods. I gave up on duplicating  
>> every method
>> (a cdef version and a python version), and am just using python  
>> methods for now.
>
> Cython has a mechanism for making C methods callable from
> Python as well as Pyrex, but last I heard, the implementation
> is incorrect in the presence of overriding+inheritance, and
> the Cython people are unwilling to pay the performance cost
> required to make it work properly.

Overriding and inheritance work for cpdef methods exactly as they do  
in Python. This has a slight speed penalty (one dictionary lookup) in  
some cases, but in the most common case it is essentially as fast as  
a cdef method.

- Robert
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.