[Cython] Bug(?): chained assignments and tuple unpacking

Alok Singhal gandalf013 at gmail.com
Wed Apr 10 22:36:27 CEST 2013


Hi,

The following code (also attached as a .pyx file) fails in the current
Cython :

cdef class test:
    pass

def main():
    cdef test a, b, c, d
    (a, b) = (c, d) = (None, None)

When run, I get the following traceback:

In [1]: import assign_test
In [2]: assign_test.main()
Traceback (most recent call last):
  File "<ipython-input-2-c2f7599d7b34>", line 1, in <module>
    assign_test.main()
  File "assign_test.pyx", line 6, in assign_test.main (assign_test.c:669)
    (a, b) = (c, d) = (None, None)
TypeError: Cannot convert NoneType to assign_test.test

I am using the latest Cython development version (from github).  Also
tested with Cython 0.18.

$ git rev-parse HEAD
e8bd1789905a58d8224e4be5019be401f360aa54

I don't get an error when I change the assignments to either:

(a, b) = (None, None)

or

a = b = None

Is this a bug in Cython?  I tried doing a git bisect and it seems like
commit ea6a71acb5c79afb080855be1cb6ca30d283ec25 is when the above code
started failing (It works with the previous commit).

Thanks,
Alok
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cython-devel/attachments/20130410/d2684b83/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: assign_test.pyx
Type: application/octet-stream
Size: 137 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/cython-devel/attachments/20130410/d2684b83/attachment.obj>


More information about the cython-devel mailing list