[Python-checkins] peps: add %r as being supported, plus minor pep8 cleanup
ethan.furman
python-checkins at python.org
Sat Mar 14 20:47:16 CET 2015
https://hg.python.org/peps/rev/7fe79194a4f2
changeset: 5730:7fe79194a4f2
user: Ethan Furman <ethan at stoneleaf.us>
date: Sat Mar 14 12:46:53 2015 -0700
summary:
add %r as being supported, plus minor pep8 cleanup
files:
pep-0461.txt | 33 ++++++++++++++++-----------------
1 files changed, 16 insertions(+), 17 deletions(-)
diff --git a/pep-0461.txt b/pep-0461.txt
--- a/pep-0461.txt
+++ b/pep-0461.txt
@@ -93,7 +93,7 @@
b'a'
``%b`` will insert a series of bytes. These bytes are collected in one of two
-ways:
+ways::
- input type supports ``Py_buffer`` [4]_?
use it to collect the necessary bytes
@@ -142,6 +142,9 @@
format; or any situation where defining ``__bytes__`` would not be appropriate
but a readable/informative representation is needed [6]_.
+``%r`` is included as a synonym for ``%a`` for the sole purpose of making 2/3
+code bases easier to maintain. Python 3 only code use ``%a`` [7]_.
+
Examples::
>>> b'%a' % 3.14
@@ -154,25 +157,19 @@
b"'def'"
-Unsupported codes
------------------
-
-``%r`` (which calls ``__repr__`` and returns a ``str``) is not supported
-(``%a`` is a good alternative, though).
-
Compatibility with Python 2
===========================
-As noted above, ``%s`` is being included solely to help ease migration from,
-and/or have a single code base with, Python 2. This is important as there
-are modules both in the wild and behind closed doors that currently use the
-Python 2 ``str`` type as a ``bytes`` container, and hence are using ``%s``
-as a bytes interpolator.
+As noted above, ``%s`` and ``%r`` are being included solely to help ease
+migration from, and/or have a single code base with, Python 2. This is
+important as there are modules both in the wild and behind closed doors that
+currently use the Python 2 ``str`` type as a ``bytes`` container, and hence
+are using ``%s`` as a bytes interpolator.
-However, ``%b`` should be used in new, Python 3 only code, so ``%s`` will
-immediately be deprecated, but not removed from the 3.x series.
-
+However, ``%b`` and ``%a`` should be used in new, Python 3 only code, so ``%s``
+and ``%r`` will immediately be deprecated, but not removed from the 3.x series
+[7]_.
Proposed variations
===================
@@ -198,7 +195,7 @@
``__format_bytes__``, etc.; such methods are not needed at this time, but can
be visited again later if real-world use shows deficiencies with this solution.
-A competing PEP, ``PEP 460 Add binary interpolation and formatting`` [7]_,
+A competing PEP, ``PEP 460 Add binary interpolation and formatting`` [8]_,
also exists.
@@ -238,7 +235,9 @@
examples: ``memoryview``, ``array.array``, ``bytearray``, ``bytes``
.. [5] http://docs.python.org/3/reference/datamodel.html#object.__bytes__
.. [6] https://mail.python.org/pipermail/python-dev/2014-February/132750.html
-.. [7] http://python.org/dev/peps/pep-0460/
+.. [7] http://bugs.python.org/issue23467 -- originally ``%r`` was not allowed,
+ but was added for consistency during the 3.5 alpha stage.
+.. [8] http://python.org/dev/peps/pep-0460/
Copyright
--
Repository URL: https://hg.python.org/peps
More information about the Python-checkins
mailing list