FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

bpo-39985: Make string.Formatter with empty field name default to 0 by tekknolagi · Pull Request #19065 · python/cpython · GitHub

Repository navigation

bpo-39985: Make string.Formatter with empty field name default to 0 - #19065

Closed
tekknolagi wants to merge 2 commits into
python:mainfrom
tekknolagi:mb-fix-string-formatter
Closed

tekknolagi wants to merge 2 commits into
python:mainfrom
tekknolagi:mb-fix-string-formatter

Conversation

tekknolagi commented Mar 19, 2020 •
edited by bedevere-bot
Loading

Copy link
Copy Markdown
Contributor

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.

https://bugs.python.org/issue39985

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I don't recall if auto-field numbering was implemented, or implemented correctly, for string.Formatter.

Comment thread Lib/test/test_string.py
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')

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Hm, okay, so I can change the test to only have 1 argument.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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).

Copy link
Copy Markdown
Contributor Author

Will update later today to take patch from https://bugs.python.org/issue27307

Copy link
Copy Markdown
Contributor

@tekknolagi, were you still looking into updating your PR with the patch? Thanks!

python-cla-bot Bot commented Apr 6, 2025

Copy link
Copy Markdown

The following commit authors need to sign the Contributor License Agreement:

github-actions Bot commented Apr 7, 2026

Copy link
Copy Markdown

This PR is stale because it has been open for 30 days with no activity.

github-actions Bot added the stale Stale PR or inactive for long period of time. label Apr 7, 2026

Copy link
Copy Markdown
Contributor Author

Sorry @csabella, I really don't have time these days. Please feel free to take over or close as appropriate.

github-actions Bot removed the stale Stale PR or inactive for long period of time. label May 10, 2026
serhiy-storchaka self-requested a review June 4, 2026 13:52

Copy link
Copy Markdown
Member

It seems this issue was fixed by #21767.

Copy link
Copy Markdown
Contributor Author

Neat, thanks

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants


Back | FazBrowse Home | New Git URL