On May 16, 2008, at 11:06 PM, Stefan Behnel wrote: > Hi, > > Robert Bradshaw wrote: >> I'm suggesting "abc" is a byte string when linked against Py2, and a >> unicode string when linked against Py3. This way string literals from >> the module have the same type as string literals in the ambient >> python environment. There is no way to say that in the above >> proposal. > > Admittedly, that's how the 2to3 tool behaves, but that's different > as it works > on the source level. So once you have invested the work to port > your code to > Py2.6 and appended all your byte string literals with a 'b', 2to3 > will do the > right thing when porting your code to Py3. > > So what you suggest is that users who want to port their Cython > code to Py3 > are required to append all their byte literals with 'b'? Then what > would be so > bad in also requiring them to add the future import at the top of > their source > file to be explicit about the requested semantics? > > Remember, automatic conversion between the two is gone in Py3. Code > that > currently assumes an equality of unicode strings and byte strings is > fundamentally broken, beyond the simple printing of strings. It > cannot be > fixed by simply transmogrifying all byte strings into unicode > strings. Plus, > what would you do about this kind of code: > > cdef char* s = _some_c_call() > result = s + "abc"
This would still work using Py2 semantics (unicode -> str is fine as long as it's ascii). > There's no "automatic" way to heal this. People *will* have to > invest work to > port their code. We can mitigate the pain. If someone writes a module in Cython for Py2, and then someone wants to use it from Py3, they should just be able to compile the C source file (not require the original author to do something special in their Cython source). - Robert _______________________________________________ Cython-dev mailing list [email protected] http://codespeak.net/mailman/listinfo/cython-dev
