Commit d928b6a9 authored by R David Murray's avatar R David Murray

#13579: minimize code base drift for 'a' string.Formatter change.

2.7 doesn't support 'a'.  This changeset ports the doc change
and clause-reording portions of Francisco Martín Brugué patch
in order to minimize code base drift.
parent 0e3a4c80
...@@ -123,8 +123,8 @@ string formatting behaviors using the same implementation as the built-in ...@@ -123,8 +123,8 @@ string formatting behaviors using the same implementation as the built-in
.. method:: format(format_string, *args, **kwargs) .. method:: format(format_string, *args, **kwargs)
:meth:`format` is the primary API method. It takes a format template :meth:`format` is the primary API method. It takes a format string and
string, and an arbitrary set of positional and keyword argument. an arbitrary set of positional and keyword arguments.
:meth:`format` is just a wrapper that calls :meth:`vformat`. :meth:`format` is just a wrapper that calls :meth:`vformat`.
.. method:: vformat(format_string, args, kwargs) .. method:: vformat(format_string, args, kwargs)
...@@ -133,8 +133,8 @@ string formatting behaviors using the same implementation as the built-in ...@@ -133,8 +133,8 @@ string formatting behaviors using the same implementation as the built-in
separate function for cases where you want to pass in a predefined separate function for cases where you want to pass in a predefined
dictionary of arguments, rather than unpacking and repacking the dictionary of arguments, rather than unpacking and repacking the
dictionary as individual arguments using the ``*args`` and ``**kwds`` dictionary as individual arguments using the ``*args`` and ``**kwds``
syntax. :meth:`vformat` does the work of breaking up the format template syntax. :meth:`vformat` does the work of breaking up the format string
string into character data and replacement fields. It calls the various into character data and replacement fields. It calls the various
methods described below. methods described below.
In addition, the :class:`Formatter` defines a number of methods that are In addition, the :class:`Formatter` defines a number of methods that are
...@@ -205,7 +205,8 @@ string formatting behaviors using the same implementation as the built-in ...@@ -205,7 +205,8 @@ string formatting behaviors using the same implementation as the built-in
Converts the value (returned by :meth:`get_field`) given a conversion type Converts the value (returned by :meth:`get_field`) given a conversion type
(as in the tuple returned by the :meth:`parse` method). The default (as in the tuple returned by the :meth:`parse` method). The default
version understands 'r' (repr) and 's' (str) conversion types. version understands 's' (str), 'r' (repr) and 'a' (ascii) conversion
types.
.. _formatstrings: .. _formatstrings:
......
...@@ -601,12 +601,12 @@ class Formatter(object): ...@@ -601,12 +601,12 @@ class Formatter(object):
def convert_field(self, value, conversion): def convert_field(self, value, conversion):
# do any conversion on the resulting object # do any conversion on the resulting object
if conversion == 'r': if conversion is None:
return repr(value) return value
elif conversion == 's': elif conversion == 's':
return str(value) return str(value)
elif conversion is None: elif conversion == 'r':
return value return repr(value)
raise ValueError("Unknown conversion specifier {0!s}".format(conversion)) raise ValueError("Unknown conversion specifier {0!s}".format(conversion))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment