[Cython] cython-devel-py3: problem with keywords
Stefan Behnel
stefan_ml at behnel.de
Sat May 17 07:47:00 CEST 2008
Hi,
Lisandro Dalcin wrote:
> I've just pulled from cython-devel-py3, and I got the following error:
>
> Traceback (most recent call last):
> File "../../test/test_environ.py", line 1, in <module>
> from mpi4py import MPI
> File "ExceptionP.pyx", line 58, in mpi4py.MPI (src/MPI.c:45238)
> error_code = property(Get_error_code, doc="error code")
> TypeError: keywords must be strings
>
> Diving inside the generated sources, it seems that keyword names in a
> call statement are being created as byte strings.
>
> Does it make sense to treat them as identifiers, putting the
> appropriate flag in the string table?
That's actually a tricky problem. Py2 does not accept unicode as keyword
arguments and Py3 requires them, so we have to distinguish between Py2 and Py3
here. However, keywords are not really identifiers. You could pass any byte
string or unicode string in Py2 using the **dict syntax.
To make things worse, Cython stores keyword arguments as a StringNode in a
generic DictItemNode of a DictNode. So I find it difficult to figure out the
right place to store the information that the string must behave like an
identifier.
BTW, Py3a5 has a bug here. It crashes when you pass byte strings as keyword
arguments to ParseTupleAndKeywords. I filed a bug report and this has been
fixed, so I guess Py3b1 will raise a TypeError.
Stefan
More information about the Cython-dev
mailing list