[Python-Dev] PEP 460 reboot (original) (raw)
Glenn Linderman v+python at g.nevcal.com
Mon Jan 13 23:46:01 CET 2014
- Previous message: [Python-Dev] PEP 460 reboot
- Next message: [Python-Dev] PEP 460 reboot
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On 1/13/2014 1:59 PM, Guido van Rossum wrote:
On Mon, Jan 13, 2014 at 1:29 PM, Glenn Linderman <v+python at g.nevcal.com> wrote:
On 1/13/2014 12:09 PM, Guido van Rossum wrote:
Yeah, the %s behavior with a string argument was a messy attempt at compromise. I was hoping to mimick a common use of %s in Python 2, where it can be used with either an 8-bit string or a number as argument, acting like %b in the former case and like %d in the latter case. Not having %s at all in Python 3 means that porting requires more thinking (== more opportunity for mistakes when you're converting in bulk) and there's no easy way to write code that works in Python 2 and 3. If we have %b for strictly interpolating bytes, I'm fine with adding %a for calling ascii() on the argument and then interpolating the result after ASCII-encoding it. If somehow (unlikely though it seems) we end up keeping %s (e.g. strictly to ease porting), we could also keep %r as an alias for %a.
%s for strictly interpolating bytes eases porting. Sad name, but good for compatibility. When the blowup happens, due to having a str type passed, the porter adds the appropriate .encode(...) to the parameter, so it doesn't blow up on Py 3, and it'll be OK for Py 2 as well, will it not? Lots of code uses %s with numbers too, and probably the occasional None or list (relying on the Python 2 near-guarantee that most objects' str() is their repr() and that repr() nearly guarantees to return only ASCII). E.g. I'm sure you can find live code doing something like headers.append('Content-Length: %s\r\n' % len(body)) That's portably fixable by switching to %d... or by adding .encode('ascii') -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-dev/attachments/20140113/fc02ccfb/attachment.html>
- Previous message: [Python-Dev] PEP 460 reboot
- Next message: [Python-Dev] PEP 460 reboot
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]