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: Improve byte formatting compatibility between Py2 and Py3
Type: enhancement Stage: resolved
Components: Interpreter Core Versions: Python 3.5
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: ethan.furman Nosy List: ethan.furman, giampaolo.rodola, gvanrossum, python-dev, serhiy.storchaka, vstinner
Priority: normal Keywords:

Created on 2015-02-15 18:33 by serhiy.storchaka, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (8)
msg236057 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2015-02-15 18:33
The main motivation of PEP 461 was to help ease migration from, and/or have a single code base with, Python 2. But bytes formatting don't support the %r code supported in Python 2. Instead it supports the %a code which is exactly equivalent to the %r code in Python 2 but doesn't supported in Python 2. So it is not so easy to migrate from or have a single code base with Python 2 it the code uses the %r opcode.

As far as bytes formatting supports the %s code (an alias to %b) purely for compatibility with Python 2, it would be good to support the %r as an alias to %a.
msg236062 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2015-02-15 19:40
Yeah, we probably got carried away by purity concerns.
msg236063 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2015-02-15 20:00
"As far as bytes formatting supports the %s code (an alias to %b) purely for compatibility with Python 2, it would be good to support the %r as an alias to %a."

I don't like this idea.
msg236068 - (view) Author: Ethan Furman (ethan.furman) * (Python committer) Date: 2015-02-15 20:28
Sometimes practicality wins; it's why we allow %s, and we should also allow %r.

Both %s and %r need to be clearly documented as an aid to Py2/3 code bases, and not recommended for new code.

Serhiy, do you have time to take of this?
msg236069 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2015-02-15 21:00
The implementation is easy -- just add "case 'r':" before "case 'a':". The hard (to me) part is the documentation, so that I'm out of the game.
msg237874 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2015-03-11 15:17
New changeset 611fa301b807 by Ethan Furman in branch 'default':
Close issue23467: add %r compatibility to bytes and bytearray
https://hg.python.org/cpython/rev/611fa301b807
msg237885 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2015-03-11 16:31
You should also update the PEP 461.
msg238099 - (view) Author: Ethan Furman (ethan.furman) * (Python committer) Date: 2015-03-14 19:49
Added in
https://hg.python.org/peps/rev/7fe79194a4f2
History
Date User Action Args
2022-04-11 14:58:12adminsetgithub: 67655
2015-03-14 19:49:14ethan.furmansetmessages: + msg238099
2015-03-11 16:31:11vstinnersetmessages: + msg237885
2015-03-11 15:17:31python-devsetstatus: open -> closed

nosy: + python-dev
messages: + msg237874

resolution: fixed
stage: resolved
2015-02-16 16:24:11giampaolo.rodolasetnosy: + giampaolo.rodola
2015-02-15 21:15:38ethan.furmansetassignee: ethan.furman
2015-02-15 21:00:03serhiy.storchakasetmessages: + msg236069
2015-02-15 20:28:09ethan.furmansetmessages: + msg236068
2015-02-15 20:00:42vstinnersetnosy: + vstinner
messages: + msg236063
2015-02-15 19:40:24gvanrossumsetmessages: + msg236062
2015-02-15 18:33:27serhiy.storchakacreate