[Python-checkins] peps: PEP 461: updates to %s and Open Questions

ethan.furman python-checkins at python.org
Wed Jan 15 03:22:53 CET 2014


http://hg.python.org/peps/rev/ded763368fae
changeset:   5350:ded763368fae
user:        Ethan Furman <ethan at stoneleaf.us>
date:        Tue Jan 14 18:23:03 2014 -0800
summary:
  PEP 461: updates to %s and Open Questions

files:
  pep-0461.txt |  26 ++++++++++++++++----------
  1 files changed, 16 insertions(+), 10 deletions(-)


diff --git a/pep-0461.txt b/pep-0461.txt
--- a/pep-0461.txt
+++ b/pep-0461.txt
@@ -44,13 +44,10 @@
     >>> b'%c' % b'a'
     b'a'
 
-%s, because it is the most general, has the most convoluted resolution:
+%s is a restricted in what it will accept::
 
-  - input type is bytes?
-    pass it straight through
-
-  - input type is numeric?
-    use its __xxx__ [1] [2] method and ascii-encode it (strictly)
+  - input type supports Py_buffer?
+    use it to collect the necessary bytes
 
   - input type is something else?
     use its __bytes__ method; if there isn't one, raise an exception [3]
@@ -61,7 +58,9 @@
     b'abc'
 
     >>> b'%s' % 3.14
-    b'3.14'
+    Traceback (most recent call last):
+    ...
+    TypeError: 3.14 has no __bytes__ method
 
     >>> b'%s' % 'hello world!'
     Traceback (most recent call last):
@@ -77,6 +76,11 @@
 
       'a string'.encode('latin-1')
 
+Unsupported % format codes
+^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+%r (which calls __repr__) is not supported
+
 
 format
 ------
@@ -88,14 +92,16 @@
 Open Questions
 ==============
 
-For %s there has been some discussion of trying to use the buffer protocol
-(Py_buffer) before trying __bytes__.  This question should be answered before
-the PEP is implemented.
+Do we need no support all the numeric format codes?  The floating point
+exponential formats seem less appropriate, for example.
 
 
 Proposed variations
 ===================
 
+It was suggested to let %s accept numbers, but since numbers have their own
+format codes this idea was discarded.
+
 It has been suggested to use %b for bytes instead of %s.
 
   - Rejected as %b does not exist in Python 2.x %-interpolation, which is

-- 
Repository URL: http://hg.python.org/peps


More information about the Python-checkins mailing list