Issue1613

classification
Title: bytes backport request
Type: Severity: minor
Components: Core Versions: 2.5.1
process
Status: closed Resolution: postponed
Dependencies: Superseder:
Assigned To: Nosy List: mcieslik, pjenvey
Priority: Keywords:

Created on 2010-05-23.02:27:01 by mcieslik, last changed 2010-05-26.18:56:58 by pjenvey.

Messages
msg5773 (view) Author: Marcin (mcieslik) Date: 2010-05-23.02:27:00
writing code targeting all of (python2.6, jython2.5.1, python3.1) is most seriously hindered (IMHO) by jython2.5.1 not supporting the b"some_chars" literal (which on python2.6+ does nothing).

use-case pseudo-code:

char = 'b' if PYTHON31 else 'c'
data = "some_chars" if JYTHON25 else eval('b"some_chars"')
array.array(CHAR, data)

line 1 is no a problem as it can be done once for the whole codebase
line 2 is problematic because it has to be done for all literals (also in unit-tests)
 
as far as I understand a syntax change from invalid -> ignore cannot break any code compatible with jython2.5.

If such a jython2.5 python2.5 inconsistency is not acceptable (or you do not plan any 2.5.x releases) could someone hint me on how to patch jython2.5.1 to develop my code easier until jython2.6 is released?
msg5774 (view) Author: Philip Jenvey (pjenvey) Date: 2010-05-23.20:56:06
The recommended way of dealing with this is to continue using str literals in your code for compatibility with 2.5, but then preprocess your code for Python 3 with the 2to3 conversion script.

The distribute installer (the replacement for setuptools) can even automatically run 2to3 on your source code for you when it's installed on Python 3

A 2.5.2 release is coming any day now, then we'll focus on 2.6 afterwards. We try to stick with mostly bug fixes for minor revisions of Python/Jython. Otherwise we can have compatibility issues -- that is, code written for 2.5.2 should work on 2.5.1 (minus bugs fixed in 2.5.2).

If you're still interested in adding bytes support for Jython 2.6, you'll basically need to modify the antlr grammar in grammar/Python.g. Python 2.6 should have tests for the new bytes syntax that you can run against
msg5775 (view) Author: Marcin (mcieslik) Date: 2010-05-24.02:02:48
Thanks for the explantation. I wrongly assumed 2to3 will not change 2.x "" to 3.x b"". It is not really obvious which conversion (to unicode or to bytes) is "right" most of the times, for example literals in exceptions
ValueError("this is really text not data") should be converted to unicode.
msg5783 (view) Author: Philip Jenvey (pjenvey) Date: 2010-05-26.18:56:57
My fault, your assumption was correct, 2to3 doesn't convert str to bytes. Maintaing 2.5 compatibility looks pretty painful, you could do something like tagging your bytes with a separate function that would encode them under 3. This obviously sucks but I don't see many other options

if sys.version_info > (3, 0):
    def b(s):
        return s.encode('latin-1')
else:
    b = str

b('some bytes')
History
Date User Action Args
2010-05-26 18:56:58pjenveysetmessages: + msg5783
2010-05-24 02:02:49mciesliksetmessages: + msg5775
2010-05-23 20:56:08pjenveysetstatus: open -> closed
resolution: postponed
messages: + msg5774
nosy: + pjenvey
2010-05-23 02:27:02mcieslikcreate