[New-bugs-announce] [issue45704] string.Formatter.parse does not handle auto-numbered positional fields

Sascha Desch report at bugs.python.org
Wed Nov 3 07:55:47 EDT 2021


New submission from Sascha Desch <sascha.desch at hotmail.com>:

It appears when adding auto-numbered positional fields in python 3.1 `Formatter.parse` was not updated to handle them and currently returns an empty string as the field name.

```
list(Formatter().parse('hello {}'))  # [('hello ', '', '', None)]
```

This does not align with `Formatter.get_field` which according to the docs: "Given field_name as returned by parse() (see above), convert it to an object to be formatted."

When supplying an empty string to `.get_field()` you get a KeyError

```
Formatter().get_field("", [1, 2, 3], {}). # raises KeyError
```

----------
messages: 405610
nosy: SDesch
priority: normal
severity: normal
status: open
title: string.Formatter.parse does not handle auto-numbered positional fields
type: behavior
versions: Python 3.10, Python 3.11, Python 3.6, Python 3.7, Python 3.8, Python 3.9

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue45704>
_______________________________________


More information about the New-bugs-announce mailing list