On Nov 24, 2009, at 11:51 PM, Stefan Behnel wrote:

> Robert Bradshaw, 25.11.2009 04:27:
>> On Nov 24, 2009, at 1:18 PM, Lisandro Dalcin wrote:
>>>> Joachim Saul, 24.11.2009 20:59:
>>>>> cdef extern from "Python.h":
>>>>>     ctypedef class __builtin__.str  [object PyStringObject]:
>>>>>         pass
>>>
>>> Anyway, any good reason for such code to fail in Cython? Should we
>>> support such declarations of builtin types? I think Cython should be
>>> able to compile as much Pyrex code as possible.
>>
>> I agree, it shouldn't fail (though perhaps there should be a  
>> warning).
>> The underlying issue is that it doesn't recognize that the user-
>> declared type could be compatible with the builtin type. We should
>> recognize this and allow it.
>
> I disagree. This would either require us to check the declaration  
> exactly
> (in which case there would be zero gain at all, as Cython would need  
> to
> know the complete type declaration already), or it would allow users  
> to
> declare all sorts of broken things on the type without checking. The  
> latter
> means that there could be all sorts of surprises for users that see  
> their
> code work or fail, depending on what they think they have declared.

I'm proposing something much simpler--if the name matches for a  
__builtin__ type, we allow assignment. If the extern declaration is  
erroneous, that will break things, but that's *always* the case with  
extern declarations. In general, a gcc error means check your extern  
declarations. (We should warn that a builtin type is being overridden.)

> I think the right way to handle this would be to finish up subtyping
> support and type fields for builtin types (IIRC, that's what's still
> missing?),

Yes, we should do this (though I'm doubtful the public and private  
APIs are all consistent from 2.3-3.x).

> and then emit either an error on the above, or a clear warning
> that states that the senseless redefinition of a builtin type has been
> ignored (which IMHO is a very good argument for making it an error).

The users type declaration would not be ignored, it would override the  
builtin one, just like

cdef extern from *:
     cdef object range(object)

would override the builtin range.

- Robert

_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to