This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: 2to3 doesn't handle byte comparison well
Type: behavior Stage: resolved
Components: 2to3 (2.x to 3.x conversion tool) Versions: Python 2.7
process
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: Nosy List: benjamin.peterson, terry.reedy, vdupras
Priority: normal Keywords:

Created on 2010-06-21 14:46 by vdupras, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (3)
msg108272 - (view) Author: Virgil Dupras (vdupras) (Python triager) Date: 2010-06-21 14:46
If we run 2to3 on the following code:

s = b' '
print s[0] == s

we end up with this:

s = b' '
print(s[0] == s)

However, the first code, under python2 prints True while the converted code, under python3 prints False.

Shouldn't 2to3 convert this code to:

s = b' '
print s[0:1] == s

instead?
msg108273 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2010-06-21 14:59
2to3 can't guess which slices are from bytes.
msg108633 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2010-06-25 21:19
Replacing string indexes with length-1 slices in the 2.x codebase, whether or not one one is running 2to3, seems to be a 'known' technique for Python3 portability and unicode-bytes inter-operability. (It was discussed this week on py-dev list .) But I do not see it mentioned in PyWiki, such as on
http://wiki.python.org/moin/PortingPythonToPy3k
History
Date User Action Args
2022-04-11 14:57:02adminsetgithub: 53289
2010-06-25 21:19:57terry.reedysetnosy: + terry.reedy
messages: + msg108633
2010-06-21 16:12:10eric.araujosetstage: resolved
2010-06-21 14:59:11benjamin.petersonsetstatus: open -> closed

nosy: + benjamin.peterson
messages: + msg108273

resolution: wont fix
2010-06-21 14:46:13vduprascreate