bpo-39985: Make string.Formatter with empty field name default to 0#19065
bpo-39985: Make string.Formatter with empty field name default to 0#19065tekknolagi wants to merge 2 commits into
Conversation
This causes string.Formatter to behave like str.format in cases like `"[0]".format((1, 2, 3))`, where `[0]` implicitly refers to the first argument to `str.format`.
ericvsmith
left a comment
There was a problem hiding this comment.
I don't recall if auto-field numbering was implemented, or implemented correctly, for string.Formatter.
| fmt = string.Formatter() | ||
| lookup = ["eggs", "and", "spam"] | ||
| self.assertEqual(fmt.format("{0[2]}{0[0]}", lookup), 'spameggs') | ||
| self.assertEqual(fmt.format("{[2]}{1[0]}", lookup, (1, 2, 3)), 'spam1') |
There was a problem hiding this comment.
This is an error with str.format:
>>> "{[2]}{1[0]}".format(["eggs", "and", "spam"], (1, 2, 3))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: cannot switch from automatic field numbering to manual field specification
There was a problem hiding this comment.
Hm, okay, so I can change the test to only have 1 argument.
There was a problem hiding this comment.
That doesn't solve the problem. If we're going to fix this, we need to make sting.Formatter work the same as str.format. The real problem here is a lack of auto-numbering support in string.Formatter (I think).
|
Will update later today to take patch from https://bugs.python.org/issue27307 |
|
@tekknolagi, were you still looking into updating your PR with the patch? Thanks! |
|
The following commit authors need to sign the Contributor License Agreement: |
|
This PR is stale because it has been open for 30 days with no activity. |
|
Sorry @csabella, I really don't have time these days. Please feel free to take over or close as appropriate. |
|
It seems this issue was fixed by #21767. |
|
Neat, thanks |
This causes string.Formatter to behave like str.format in cases like
"[0]".format((1, 2, 3)), where[0]implicitly refers to the firstargument to
str.format.https://bugs.python.org/issue39985