This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Erroneous reference to "integer" in format string grammar
Type: Stage: resolved
Components: Documentation Versions: Python 3.1, Python 3.2, Python 3.3, Python 3.4, Python 2.7, Python 2.6
process
Status: closed Resolution: duplicate
Dependencies: Superseder: Format mini-language integer definition is incorrect
View: 32720
Assigned To: eric.smith Nosy List: davidchambers, docs@python, eric.smith, georg.brandl
Priority: normal Keywords:

Created on 2013-10-06 04:14 by davidchambers, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (2)
msg199024 - (view) Author: David Chambers (davidchambers) Date: 2013-10-06 04:14
I first raised this issue on Stack Overflow: http://stackoverflow.com/questions/19203194

The [replacement field grammar][1] states that an [integer][2] is a valid field_name, but this is inaccurate:

    >>> '{0}'.format('zero')
    'zero'
    >>> '{0x0}.format('zero')
    KeyError: '0x0'
    >>> '{0o0}.format('zero')
    KeyError: '0o0'
    >>> '{0b0}.format('zero')
    KeyError: '0b0'

This [comment][3] by Eric Smith suggests that the above is the intended behaviour:

> get_integer uses the narrowest possible definition for integer indexes,
> in order to pass all other strings to mappings.

The documentation should be updated to match the actual behaviour. abarnert on Stack Overflow suggested the following change:

    -arg_name          ::=  [identifier | integer]
    +arg_name          ::=  [identifier | digit+]


[1]: http://docs.python.org/2/library/string.html#format-string-syntax
[2]: http://docs.python.org/2/reference/lexical_analysis.html#grammar-token-integer
[3]: http://bugs.python.org/issue8985#msg107705
msg199033 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2013-10-06 06:46
The bug is that "integer" links to the "integer" production in the Python grammar.  This shouldn't happen; I'll have a look on the Sphinx side.

As a workaround, "integer" can be replaced by "digit+" as requested (it occurs twice).
History
Date User Action Args
2022-04-11 14:57:51adminsetgithub: 63374
2019-05-17 12:52:34cheryl.sabellasetstatus: open -> closed
superseder: Format mini-language integer definition is incorrect
resolution: duplicate
stage: resolved
2013-10-06 06:46:10georg.brandlsetassignee: docs@python -> eric.smith

nosy: + eric.smith
2013-10-06 06:46:03georg.brandlsetnosy: + georg.brandl
messages: + msg199033
2013-10-06 04:14:24davidchamberscreate