On May 16, 2008, at 3:23 AM, Stefan Behnel wrote:

> Hi,
>
> Robert Bradshaw wrote:
>> I would rather that string literals be interpreted according to the C
>> library they're linked against. I'm also thinking about code that,
>> say, returns string literals. I would much rather it returns str in
>> Py2 and unicode in Py3.
>
> That would be unexpected, especially in Py3 where the two are  
> distinct types.

They are two distinct types in Py2 as well. (Well, str is being  
renamed to bytes, and unicode to str?)

> As I said to Lisandro in another post:
>
> S> If you want source compatibility, you can't change the semantics  
> based on
> S> the compile time environment - except for the cases where the  
> runtime
> S> environments really differ (such as byte/unicode identifiers).  
> Imagine you
> S> had some latin-1 encoded XML byte literal in your code. In Py2,  
> under your
> S> proposal, this would become a byte string that can be parsed. In  
> Py3,
> S> however, this would suddenly become a unicode string and the  
> parser would
> S> refuse to handle it, as it's no longer ISO encoded.

Yes, I saw this. I don't see how this is an issue--due to your work  
implementing PEP 263 any string literal has a well-defined unicode  
meaning.

>> Note, this is not something that needs to be done to get ready for
>> Py3--it's an assumption that unqualified string literals are the same
>> type as python identifiers.
>
> This happens to be a correct assumption in Py2 and Py3, but I don't  
> see the link.
>
>
>> I was doing some playing around with str and unicode in Python, and I
>> noticed that it will automatically convert between the two (no
>> explicit encoding needed) as long as the data in question is pure
>> ASCII.
>
> That would be Py2. Py3 will never attempt any kind of automatic  
> conversion
> between bytes and str. And I am convinced that Cython shouldn't do  
> that either.

I haven't played with Py3. I was actually (pleasantly) surprised it  
worked in Py2, but if it's being discontinued then it doesn't help my  
case. But it does mean that stuff like

--- a.pyx ---

def foo(x):
     if x > 0:
         return "good"
     else:
         return "bad"
-------------

import a
print "3 is %s" % a.foo(3)

won't work in both Py2 and Py3, which I think it should. "Principle  
of least surprise."

- Robert

_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to