Lisandro Dalcin wrote:
> On Tue, Oct 20, 2009 at 6:50 AM, Stefan Behnel wrote:
>> Robert Bradshaw wrote:
>>> On Oct 19, 2009, at 5:09 PM, Neal Becker wrote:
>>>
>>>> Lisandro Dalcin wrote:
>>>>
>>>> ...
>>>>> A possible backward way could be to introduce (slightly) new syntax,
>>>>> something like <SomeType??>, i.e using two '?' to indicate a
>>>>> "stronger" type check disallowing None...
>>>> That would be spelled <SomeType?!>
>>>> :)
>>> Well, or one could use the nonecheck directive. I'd like to avoid
>>> adding more syntax for a problem that'll go away with a smarter
>>> compiler.
>> +1
>>
>> I also think that the chance of breaking code with this change is rather
>> small. I can't imagine that many use cases where I would cast a value to a
>> specific extension type other than accessing its C attributes or methods,
>> which would clearly lead to a crash for None values. So however people used
>> this feature before, I expect a None check to be very close in the code.
>
> OK, patch uploaded:
> http://trac.cython.org/cython_trac/attachment/ticket/417/typetest.diff
According to the test case, this passes, also at runtime:
cdef Foo x = <Foo>None
but this fails at runtime:
cdef Foo x = <Foo?>None
Looks a bit funny at first sight, but becomes a feature when you think
about it.
> Please review, and let me know if it is good enough for pushing...
Regarding the naming, you called the flag "notnone", but used it as "not
notnone" or "none_allowed" in most places. Why not call it "none_allowed"
everywhere instead?
Regarding likely() and '||' tests, I usually prefer duplicating the
likely() around each subexpression. I'm not sure what the C compiler will
make from the or-ed expression if you use only one likely(), but each
subexpression is always evaluated by itself, and in almost all cases, it is
also likely true by itself.
I noticed that you added %.200s for type name formatting. Good catch.
If you could fix the two remarks above, I'm fine with pushing it.
> BTW, there is one usage of PyTypeTestNode at
> Cython/Compiler/Optimize.py ... Should we pass notnone=True there?
Yes. The optimisations there require exact type tests.
Stefan
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev