Dag, you proposal is a strong one. Just pulled from cython-dagss. Then
some comments below.
Could you optimize the case below?
def default(MyClass var):
if var is None: var = MyClass(4, 5)
print var.a
Additionally, no checks should be done in this case:
def strinct(MyClass var not None):
print var.a
On Thu, Aug 21, 2008 at 1:33 PM, Dag Sverre Seljebotn
<[EMAIL PROTECTED]> wrote:
> Lisandro Dalcin wrote:
>> On Wed, Aug 20, 2008 at 9:28 PM, Greg Ewing <[EMAIL PROTECTED]>
>> wrote:
>>> Speaking of that, I've been thinking for a while now
>>> about making "not None" the default, and requiring
>>> "or None" to specify that None is an acceptable
>>> parameter value.
>>
>> Definitely +1 for me.
>>
>>> Having seen a number of pieces of Pyrex code that
>>> were susceptible to being crashed because "not None"
>>> wasn't used where it should have been, I think
>>> this would be a safer default.
>>
>> Indeed. My own code suffered for this flaw, I realized about this
>> Cython behavior reading the generated C code, and then I went to the
>> docs to comfirm this. Up to now, I'm not yet completelly sure that all
>> my code is free of "None" crashes.
>>
>>> The change may
>>> break some existing code, though.
>>
>> Yes, but surely is will make others codes to become correct.
>
> But it does it by making a hard restriction on what kind of code you can
> write -- I'd like to be able to pass None to functions (in a safe manner),
> not just disable the feature.
>
> If you make this change now you essentially "can't go back" since you will
> then get code written which may depend on None being checked for at the
> beginning of the function. So it's a one way change, and we do get results
> more quickler but OTOH we permanently say no to (in my opinion) nicer
> behaviour.
>
> We all agree that segfaults are not nice, I just think the exception
> should be raised when accessing the field/attribute rather than when
> entering the function... (i.e. go the Java way like in the prototype I
> recently posted, see the behaviour in
>
> http://hg.cython.org/cython-dagss/file/4d543e06c926/tests/run/noneattributeacc.pyx
>
> ).
>
> Dag Sverre
>
> _______________________________________________
> Cython-dev mailing list
> [email protected]
> http://codespeak.net/mailman/listinfo/cython-dev
>
--
Lisandro Dalcín
---------------
Centro Internacional de Métodos Computacionales en Ingeniería (CIMEC)
Instituto de Desarrollo Tecnológico para la Industria Química (INTEC)
Consejo Nacional de Investigaciones Científicas y Técnicas (CONICET)
PTLC - Güemes 3450, (3000) Santa Fe, Argentina
Tel/Fax: +54-(0)342-451.1594
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev