[Cython] from __future__ import ...
Stefan Behnel
stefan_ml at behnel.de
Thu May 15 22:03:29 CEST 2008
Hi,
Lisandro Dalcin wrote:
> I definitelly disagree with you. Cython 'pyx' has the chance of being
> more backward compatible even that source 'py' files.
That's why I'm asking. There are reasons for and against this idea.
> I would instead propose the following:
>
> * Iff 'from __future__ import unicode_literals' is issued, then Cython
> should generate unicode strings REGARDELESS of the C-generated compile
> time Python version. In Py2.X, that would be 'unicode' type, and in
> Py3, 'str' type.
Sure.
> * Iff 'from __future__ import unicode_literals' is NOT issued, then at
> compile time, Cython should create strings as is the default in the
> compile-time Python version, that is, (byte) 'str' type as in Py2, or
> (unicode) 'str' type as in Py3.
This contradicts what you said above. If you want source compatibility, you
can't change the semantics based on the compile time environment - except for
the cases where the runtime environments really differ (such as byte/unicode
identifiers). Imagine you had some latin-1 encoded XML byte literal in your
code. In Py2, under your proposal, this would become a byte string that can be
parsed. In Py3, however, this would suddenly become a unicode string and the
parser would refuse to handle it, as it's no longer ISO encoded.
> * Iff string literals are prefixed with 'b' as in b"abc", then Cython
> sould create at compile time a (byte) 'str' type object in the case of
> Py2.X (note: Python2.6 already does this), and a 'bytes' instance in
> the case of Py3.
That's the right thing to do.
Stefan
More information about the Cython-dev
mailing list