On Oct 21, 2009, at 9:56 AM, Lisandro Dalcin wrote: > On Tue, Oct 20, 2009 at 6:50 AM, Stefan Behnel <[email protected]> > 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 > > Please review, and let me know if it is good enough for pushing...
I'd either make the function inline or split it up into two functions so that the none_allowed argument (and possibly check for none) can be eliminated at compile time. > BTW, there is one usage of PyTypeTestNode at > Cython/Compiler/Optimize.py ... Should we pass notnone=True there? Probably not to be safe, but Stefan wrote this code, so he'd know better than I. - Robert _______________________________________________ Cython-dev mailing list [email protected] http://codespeak.net/mailman/listinfo/cython-dev
