diff options
author | R David Murray <rdmurray@bitdance.com> | 2012-08-19 17:57:29 -0400 |
---|---|---|
committer | R David Murray <rdmurray@bitdance.com> | 2012-08-19 17:57:29 -0400 |
commit | d928b6a96516f611583310fd41c6c905562acd2c (patch) | |
tree | 396d0687ba8128e6c1f66f854677bcd14b455cee | |
parent | 0e3a4c80585ce993dc274b6cea31f283948e1c44 (diff) | |
download | cpython-git-d928b6a96516f611583310fd41c6c905562acd2c.tar.gz |
#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.
-rw-r--r-- | Doc/library/string.rst | 11 | ||||
-rw-r--r-- | Lib/string.py | 8 |
2 files changed, 10 insertions, 9 deletions
diff --git a/Doc/library/string.rst b/Doc/library/string.rst index 0eda746ede..ef1a0c265b 100644 --- a/Doc/library/string.rst +++ b/Doc/library/string.rst @@ -123,8 +123,8 @@ string formatting behaviors using the same implementation as the built-in .. method:: format(format_string, *args, **kwargs) - :meth:`format` is the primary API method. It takes a format template - string, and an arbitrary set of positional and keyword argument. + :meth:`format` is the primary API method. It takes a format string and + an arbitrary set of positional and keyword arguments. :meth:`format` is just a wrapper that calls :meth:`vformat`. .. method:: vformat(format_string, args, kwargs) @@ -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 dictionary of arguments, rather than unpacking and repacking the dictionary as individual arguments using the ``*args`` and ``**kwds`` - syntax. :meth:`vformat` does the work of breaking up the format template - string into character data and replacement fields. It calls the various + syntax. :meth:`vformat` does the work of breaking up the format string + into character data and replacement fields. It calls the various methods described below. 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 Converts the value (returned by :meth:`get_field`) given a conversion type (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: diff --git a/Lib/string.py b/Lib/string.py index 9c0ebe1fd4..97278034a0 100644 --- a/Lib/string.py +++ b/Lib/string.py @@ -601,12 +601,12 @@ class Formatter(object): def convert_field(self, value, conversion): # do any conversion on the resulting object - if conversion == 'r': - return repr(value) + if conversion is None: + return value elif conversion == 's': return str(value) - elif conversion is None: - return value + elif conversion == 'r': + return repr(value) raise ValueError("Unknown conversion specifier {0!s}".format(conversion)) |