[Pyrex] [Cython] Proposed change to behaviour of "not None"
Dag Sverre Seljebotn
dagss at student.matnat.uio.no
Thu Aug 21 13:42:09 CEST 2008
Dag Sverre Seljebotn wrote:
> [1] Like just checking if you're within an if-test where the local
> variable was checked to not be None + only the first attribute lookup on
> a local variable in the same block needs a check, because an exception
> drops you out of it. These two rules gets you a long way.
>
(All this Cython only but keeping the thread intact...)
Sorry: And any assignments to a local variable will reset the state to
now known, that must be dealt with too. I'm not saying that this is a
magic bullet, just that code like
cdef MyClass x = ...
if x is not None:
block without assignment to x
could be a convenient way to declare intent and generate efficient code
(kind of like how if-statements are currently translated to switch
statements under certain strict conditions)
(Hmm, in that view, a special type like cython.nonnone(MyClass) is
perhaps not needed, an "assert x is not None" after every assignment to
x could fill the same role)
--
Dag Sverre
More information about the Pyrex
mailing list