[Cython] CPython incompatibility in string literal concatenation

Jelle Zijlstra jelle.zijlstra at gmail.com
Sun Sep 13 21:00:35 CEST 2015


While implementing PEP 498 I found a minor incompatibility between
CPython and Cython: CPython lets you concatenate u-prefixed and
non-prefixed string literals, while Cython throws an error.

jelle at devjelle:~/cython$ cat concat.py
print(u'foo' 'bar')

jelle at devjelle:~/cython$ python concat.py
foobar
jelle at devjelle:~/cython$ cython concat.py

Error compiling Cython file:
------------------------------------------------------------
...
print(u'foo' 'bar')
            ^
------------------------------------------------------------

concat.py:1:13: Cannot mix string literals of different types,
expected u'', got ''


I tried both CPython 2.7 and 3.5. The documentation at
https://docs.python.org/2/reference/lexical_analysis.html#string-literal-concatenation
is ambiguous as to whether this behavior is intentional.

As part of implementing PEP 498, I can make Cython's behavior match
CPython's, unless there's a good reason to keep the incompatibility.


More information about the cython-devel mailing list