Skip to content

Commit bf44aa3

Browse files
wjandreaAA-Turnerskirpichev
authored andcommitted
Docs: Link tokens in the format string grammars (python#108184)
Co-authored-by: Adam Turner <[email protected]> Co-authored-by: Sergey B Kirpichev <[email protected]>
1 parent a3cfa16 commit bf44aa3

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

Doc/library/string.rst

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -208,13 +208,13 @@ The grammar for a replacement field is as follows:
208208

209209
.. productionlist:: format-string
210210
replacement_field: "{" [`field_name`] ["!" `conversion`] [":" `format_spec`] "}"
211-
field_name: arg_name ("." `attribute_name` | "[" `element_index` "]")*
212-
arg_name: [`identifier` | `digit`+]
213-
attribute_name: `identifier`
214-
element_index: `digit`+ | `index_string`
211+
field_name: `arg_name` ("." `attribute_name` | "[" `element_index` "]")*
212+
arg_name: [`~python-grammar:identifier` | `~python-grammar:digit`+]
213+
attribute_name: `~python-grammar:identifier`
214+
element_index: `~python-grammar:digit`+ | `index_string`
215215
index_string: <any source character except "]"> +
216216
conversion: "r" | "s" | "a"
217-
format_spec: <described in the next section>
217+
format_spec: `format-spec:format_spec`
218218

219219
In less formal terms, the replacement field can start with a *field_name* that specifies
220220
the object whose value is to be formatted and inserted
@@ -316,9 +316,9 @@ The general form of a *standard format specifier* is:
316316
fill: <any character>
317317
align: "<" | ">" | "=" | "^"
318318
sign: "+" | "-" | " "
319-
width: `digit`+
319+
width: `~python-grammar:digit`+
320320
grouping_option: "_" | ","
321-
precision: `digit`+
321+
precision: `~python-grammar:digit`+
322322
type: "b" | "c" | "d" | "e" | "E" | "f" | "F" | "g" | "G" | "n" | "o" | "s" | "x" | "X" | "%"
323323

324324
If a valid *align* value is specified, it can be preceded by a *fill*

Doc/tools/.nitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ Doc/library/smtplib.rst
7777
Doc/library/socket.rst
7878
Doc/library/ssl.rst
7979
Doc/library/stdtypes.rst
80-
Doc/library/string.rst
8180
Doc/library/subprocess.rst
8281
Doc/library/termios.rst
8382
Doc/library/test.rst

Doc/tools/extensions/pyspecific.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@
4848
Body.enum.converters['lowerroman'] = \
4949
Body.enum.converters['upperroman'] = lambda x: None
5050

51+
# monkey-patch the productionlist directive to allow hyphens in group names
52+
# https://github.com/sphinx-doc/sphinx/issues/11854
53+
from sphinx.domains import std
54+
55+
std.token_re = re.compile(r'`((~?[\w-]*:)?\w+)`')
5156

5257
# Support for marking up and linking to bugs.python.org issues
5358

0 commit comments

Comments
 (0)