On Fri, 07 Jun 2013 19:10:34 +0600, Stefan Behnel <stefan...@behnel.de> wrote:

Nikita Nemkin, 07.06.2013 13:24:
Currently, conditional casts like <Name?>obj do not allow None values.

This might seem like an inconsistency, because <Name>obj does allow None
values, just like a normal assignment. However, it's a special case that
asks explicitly for the given type, so I think it's ok to be stricter.


I have found it useful to allow None sometimes.
The syntax could be one of:
 * <Name or None?>obj
 * <Name? or None>obj
 * <Name??>obj

Use case (without this feature):

    tn_obj = self.any.non_trivial.nullable.expression()
    cdef TypeName tn
    if tn_obj is not None:
        tn = <TypeName?>tn_obj
        ...

Use case (with this feature):

    cdef TypeName tn = <TypeName or
None?>self.any.non_trivial.nullable.expression()
    if tn is not None:
        ...

Why not just

    cdef TypeName tn = self.any.non_trivial.nullable.expression()
    if tn is not None:
        ...

?

I.e. why do you need that cast in the first place?

You are right. The behavior I want is actually the default
assignment behavior.
Writing almost fully typed code, I started to percieve Cython
as a statically typed language...

Please disregard my feature request and thank you.


Best regards,
Nikita Nemkin
_______________________________________________
cython-devel mailing list
cython-devel@python.org
http://mail.python.org/mailman/listinfo/cython-devel

Reply via email to