mirror of
https://github.com/python/cpython.git
synced 2025-07-19 01:05:26 +00:00
gh-71494: string.Formatter: support keys/attributes in unnumbered fields (GH-21767)
This commit is contained in:
parent
0373926260
commit
22b2d37f42
3 changed files with 28 additions and 7 deletions
|
@ -212,19 +212,20 @@ class Formatter:
|
|||
# this is some markup, find the object and do
|
||||
# the formatting
|
||||
|
||||
# handle arg indexing when empty field_names are given.
|
||||
if field_name == '':
|
||||
# handle arg indexing when empty field first parts are given.
|
||||
field_first, _ = _string.formatter_field_name_split(field_name)
|
||||
if field_first == '':
|
||||
if auto_arg_index is False:
|
||||
raise ValueError('cannot switch from manual field '
|
||||
'specification to automatic field '
|
||||
'numbering')
|
||||
field_name = str(auto_arg_index)
|
||||
field_name = str(auto_arg_index) + field_name
|
||||
auto_arg_index += 1
|
||||
elif field_name.isdigit():
|
||||
elif isinstance(field_first, int):
|
||||
if auto_arg_index:
|
||||
raise ValueError('cannot switch from manual field '
|
||||
'specification to automatic field '
|
||||
'numbering')
|
||||
raise ValueError('cannot switch from automatic field '
|
||||
'numbering to manual field '
|
||||
'specification')
|
||||
# disable auto arg incrementing, if it gets
|
||||
# used later on, then an exception will be raised
|
||||
auto_arg_index = False
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue