[Cython] from __future__ import ...
Stefan Behnel
stefan_ml at behnel.de
Fri May 16 18:16:46 CEST 2008
Hi Lisandro,
please read what I post. You've been stating repeatedly that your experience
with Unicode is limited, and I think I have told you a lot of what I know
about the subject. I appreciate discussion, but please consider that I might
have more reasons for my opinions about the subject than I state in each
single post.
Lisandro Dalcin wrote:
> On 5/16/08, Stefan Behnel <stefan_ml at behnel.de> wrote:
>> The thing is that if you write
>>
>> getattr(o, u"attr")
>>
>> in Cython, it will work in both Py2 and Py3. However,
>>
>> getattr(o, "attr")
>>
>> will only work in Py2, unless you do the future import.
>
> Stefan, I understood that one of the traget of Cython is to
> efficiently compile Python code. Please note that
>
> getattr(o, u"attr")
>
> is not valid Python 3 code at all !!
That's why I said "in Cython".
> You are proposing that if I do "def foo(): ..." the the identifier
> 'foo' will be implicitely treated as unicode for Py3,
Sure. You didn't state in your source that you wanted the identifier name to
be a byte string, did you? (which was obviously because Python doesn't allow
you to do that).
> but a string literal "abc" do not !!.
Because the syntax of Python2, which Cython currently implements, dictates
that "abc" is a byte string. This is explicit in Python2, as the unicode
string would be u"abc".
The difference between identifiers and strings is that one is a name and the
other is a piece of data. The language can do whatever it likes with the names
(it can even strip them from the compiled result completely), but it must
*never* corrupt data.
Py3 has come a long way since the initial Unicode support in Py 2.0, almost
eight years back. We shouldn't throw all lessons learned away and think we can
do better.
Stefan
More information about the Cython-dev
mailing list