Fix formatting.

This commit is contained in:
Antoine Pitrou 2014-01-21 22:24:03 +01:00
parent d98a48bde3
commit aff226c1bd
1 changed files with 13 additions and 14 deletions

View File

@ -59,15 +59,15 @@ Example:
>>> b'%c' % b'a'
b'a'
``%s`` is restricted in what it will accept::
``%s`` is restricted in what it will accept:
- input type supports ``Py_buffer`` [4]_?
use it to collect the necessary bytes
- input type supports ``Py_buffer`` [4]_?
use it to collect the necessary bytes
- input type is something else?
use its ``__bytes__`` method [5]_ ; if there isn't one, raise a ``TypeError``
- input type is something else?
use its ``__bytes__`` method [5]_ ; if there isn't one, raise a ``TypeError``
Examples:
Examples::
>>> b'%s' % b'abc'
b'abc'
@ -83,7 +83,6 @@ Examples:
TypeError: 'hello world' has no __bytes__ method, perhaps you need to encode it?
.. note::
Because the ``str`` type does not have a ``__bytes__`` method, attempts to
directly use ``'a string'`` as a bytes interpolation value will raise an
exception. To use ``'string'`` values, they must be encoded or otherwise
@ -116,21 +115,21 @@ 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
why we are using ``%s``.
- Rejected as ``%b`` does not exist in Python 2.x %-interpolation, which is
why we are using ``%s``.
It has been proposed to automatically use ``.encode('ascii','strict')`` for
``str`` arguments to ``%s``.
- Rejected as this would lead to intermittent failures. Better to have the
operation always fail so the trouble-spot can be correctly fixed.
- Rejected as this would lead to intermittent failures. Better to have the
operation always fail so the trouble-spot can be correctly fixed.
It has been proposed to have ``%s`` return the ascii-encoded repr when the
value is a ``str`` (b'%s' % 'abc' --> b"'abc'").
- Rejected as this would lead to hard to debug failures far from the problem
site. Better to have the operation always fail so the trouble-spot can be
easily fixed.
- Rejected as this would lead to hard to debug failures far from the problem
site. Better to have the operation always fail so the trouble-spot can be
easily fixed.
Originally this PEP also proposed adding format style formatting, but it
was decided that format and its related machinery were all strictly text