Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 46988d3

Browse files
committed
Merge string formatting doc fixes from 3.5
2 parents a0fcaca + d5db147 commit 46988d3

9 files changed

Lines changed: 31 additions & 29 deletions

File tree

Doc/faq/programming.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -839,7 +839,7 @@ How do I convert a number to a string?
839839
To convert, e.g., the number 144 to the string '144', use the built-in type
840840
constructor :func:`str`. If you want a hexadecimal or octal representation, use
841841
the built-in functions :func:`hex` or :func:`oct`. For fancy formatting, see
842-
the :ref:`string-formatting` section, e.g. ``"{:04d}".format(144)`` yields
842+
the :ref:`formatstrings` section, e.g. ``"{:04d}".format(144)`` yields
843843
``'0144'`` and ``"{:.3f}".format(1.0/3.0)`` yields ``'0.333'``.
844844

845845

Doc/library/datetime.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,7 @@ Instance methods:
604604

605605
.. method:: date.__format__(format)
606606

607-
Same as :meth:`.date.strftime`. This makes it possible to specify format
607+
Same as :meth:`.date.strftime`. This makes it possible to specify a format
608608
string for a :class:`.date` object when using :meth:`str.format`. For a
609609
complete list of formatting directives, see
610610
:ref:`strftime-strptime-behavior`.
@@ -1179,7 +1179,7 @@ Instance methods:
11791179

11801180
.. method:: datetime.__format__(format)
11811181

1182-
Same as :meth:`.datetime.strftime`. This makes it possible to specify format
1182+
Same as :meth:`.datetime.strftime`. This makes it possible to specify a format
11831183
string for a :class:`.datetime` object when using :meth:`str.format`. For a
11841184
complete list of formatting directives, see
11851185
:ref:`strftime-strptime-behavior`.
@@ -1424,7 +1424,7 @@ Instance methods:
14241424

14251425
.. method:: time.__format__(format)
14261426

1427-
Same as :meth:`.time.strftime`. This makes it possible to specify format string
1427+
Same as :meth:`.time.strftime`. This makes it possible to specify a format string
14281428
for a :class:`.time` object when using :meth:`str.format`. For a
14291429
complete list of formatting directives, see
14301430
:ref:`strftime-strptime-behavior`.

Doc/library/enum.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -555,12 +555,12 @@ Some rules:
555555
3. When another data type is mixed in, the :attr:`value` attribute is *not the
556556
same* as the enum member itself, although it is equivalent and will compare
557557
equal.
558-
4. %-style formatting: `%s` and `%r` call :class:`Enum`'s :meth:`__str__` and
559-
:meth:`__repr__` respectively; other codes (such as `%i` or `%h` for
560-
IntEnum) treat the enum member as its mixed-in type.
561-
5. :meth:`str.__format__` (or :func:`format`) will use the mixed-in
562-
type's :meth:`__format__`. If the :class:`Enum`'s :func:`str` or
563-
:func:`repr` is desired use the `!s` or `!r` :class:`str` format codes.
558+
4. %-style formatting: `%s` and `%r` call the :class:`Enum` class's
559+
:meth:`__str__` and :meth:`__repr__` respectively; other codes (such as
560+
`%i` or `%h` for IntEnum) treat the enum member as its mixed-in type.
561+
5. :meth:`str.format` (or :func:`format`) will use the mixed-in
562+
type's :meth:`__format__`. If the :class:`Enum` class's :func:`str` or
563+
:func:`repr` is desired, use the `!s` or `!r` format codes.
564564

565565

566566
Interesting examples

Doc/library/pprint.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ are converted to strings. The default implementation uses the internals of the
197197
the current presentation context (direct and indirect containers for *object*
198198
that are affecting the presentation) as the keys; if an object needs to be
199199
presented which is already represented in *context*, the third return value
200-
should be ``True``. Recursive calls to the :meth:`format` method should add
200+
should be ``True``. Recursive calls to the :meth:`.format` method should add
201201
additional entries for containers to this dictionary. The third argument,
202202
*maxlevels*, gives the requested limit to recursion; this will be ``0`` if there
203203
is no requested limit. This argument should be passed unmodified to recursive

Doc/library/stdtypes.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1450,7 +1450,7 @@ multiple fragments.
14501450

14511451
For more information on the ``str`` class and its methods, see
14521452
:ref:`textseq` and the :ref:`string-methods` section below. To output
1453-
formatted strings, see the :ref:`string-formatting` section. In addition,
1453+
formatted strings, see the :ref:`formatstrings` section. In addition,
14541454
see the :ref:`stringservices` section.
14551455

14561456

Doc/library/string.rst

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,14 @@ The constants defined in this module are:
7575

7676
.. _string-formatting:
7777

78-
String Formatting
79-
-----------------
78+
Custom String Formatting
79+
------------------------
8080

8181
The built-in string class provides the ability to do complex variable
82-
substitutions and value formatting via the :func:`format` method described in
82+
substitutions and value formatting via the :meth:`~str.format` method described in
8383
:pep:`3101`. The :class:`Formatter` class in the :mod:`string` module allows
8484
you to create and customize your own string formatting behaviors using the same
85-
implementation as the built-in :meth:`format` method.
85+
implementation as the built-in :meth:`~str.format` method.
8686

8787

8888
.. class:: Formatter
@@ -91,9 +91,9 @@ implementation as the built-in :meth:`format` method.
9191

9292
.. method:: format(format_string, *args, **kwargs)
9393

94-
:meth:`format` is the primary API method. It takes a format string and
94+
The primary API method. It takes a format string and
9595
an arbitrary set of positional and keyword arguments.
96-
:meth:`format` is just a wrapper that calls :meth:`vformat`.
96+
It is just a wrapper that calls :meth:`vformat`.
9797

9898
.. deprecated:: 3.5
9999
Passing a format string as keyword argument *format_string* has been
@@ -267,8 +267,9 @@ Most built-in types support a common formatting mini-language, which is
267267
described in the next section.
268268

269269
A *format_spec* field can also include nested replacement fields within it.
270-
These nested replacement fields can contain only a field name; conversion flags
271-
and format specifications are not allowed. The replacement fields within the
270+
These nested replacement fields may contain a field name, conversion flag
271+
and format specification, but deeper nesting is
272+
not allowed. The replacement fields within the
272273
format_spec are substituted before the *format_spec* string is interpreted.
273274
This allows the formatting of a value to be dynamically specified.
274275

@@ -306,8 +307,10 @@ The general form of a *standard format specifier* is:
306307

307308
If a valid *align* value is specified, it can be preceded by a *fill*
308309
character that can be any character and defaults to a space if omitted.
309-
Note that it is not possible to use ``{`` and ``}`` as *fill* char while
310-
using the :meth:`str.format` method; this limitation however doesn't
310+
It is not possible to use a literal curly brace ("``{``" or "``}``") as
311+
the *fill* character when using the :meth:`str.format`
312+
method. However, it is possible to insert a curly brace
313+
with a nested replacement field. This limitation doesn't
311314
affect the :func:`format` function.
312315

313316
The meaning of the various alignment options is as follows:
@@ -496,8 +499,8 @@ The available presentation types for floating point and decimal values are:
496499
Format examples
497500
^^^^^^^^^^^^^^^
498501

499-
This section contains examples of the new format syntax and comparison with
500-
the old ``%``-formatting.
502+
This section contains examples of the :meth:`str.format` syntax and
503+
comparison with the old ``%``-formatting.
501504

502505
In most of the cases the syntax is similar to the old ``%``-formatting, with the
503506
addition of the ``{}`` and with ``:`` used instead of ``%``.

Doc/library/tracemalloc.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,7 @@ Traceback
620620
*limit* is set, only format the *limit* most recent frames.
621621

622622
Similar to the :func:`traceback.format_tb` function, except that
623-
:meth:`format` does not include newlines.
623+
:meth:`.format` does not include newlines.
624624

625625
Example::
626626

Doc/tools/susp-ignored.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ howto/pyporting,,::,Programming Language :: Python :: 2
8282
howto/pyporting,,::,Programming Language :: Python :: 3
8383
howto/regex,,::,
8484
howto/regex,,:foo,(?:foo)
85-
howto/urllib2,,:example,"for example ""joe@password:example.com"""
85+
howto/urllib2,,:password,"for example ""joe:password@example.com"""
8686
library/audioop,,:ipos,"# factor = audioop.findfactor(in_test[ipos*2:ipos*2+len(out_test)],"
8787
library/bisect,32,:hi,all(val >= x for val in a[i:hi])
8888
library/bisect,42,:hi,all(val > x for val in a[i:hi])

Doc/tutorial/introduction.rst

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -352,9 +352,8 @@ The built-in function :func:`len` returns the length of a string::
352352
Strings support a large number of methods for
353353
basic transformations and searching.
354354

355-
:ref:`string-formatting`
356-
Information about string formatting with :meth:`str.format` is described
357-
here.
355+
:ref:`formatstrings`
356+
Information about string formatting with :meth:`str.format`.
358357

359358
:ref:`old-string-formatting`
360359
The old formatting operations invoked when strings and Unicode strings are

0 commit comments

Comments
 (0)