Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

string.Formatter does not handle non-indexed item and attribute access #129273

Open
dg-pb opened this issue Jan 25, 2025 · 3 comments
Open

string.Formatter does not handle non-indexed item and attribute access #129273

dg-pb opened this issue Jan 25, 2025 · 3 comments
Labels
type-bug An unexpected behavior, bug, or error

Comments

@dg-pb
Copy link
Contributor

dg-pb commented Jan 25, 2025

Bug report

Bug description:

from argparse import Namespace
fmt = '{[0]} {.a}'
fmt.format([10], Namespace(a=1))    # '10 1'

# ---

import string
string.Formatter().format(fmt, [10], Namespace(a=1))
# KeyError: ''

CPython versions tested on:

3.14

Operating systems tested on:

macOS

@dg-pb dg-pb added the type-bug An unexpected behavior, bug, or error label Jan 25, 2025
@dg-pb
Copy link
Contributor Author

dg-pb commented Jan 25, 2025

It is arguably a missing feature and not a bug, but I would say it is a bug given this statement in docs:
"The Formatter class in the string module allows you to create and customize your own string formatting behaviors using the same implementation as the built-in format() method."

@dg-pb
Copy link
Contributor Author

dg-pb commented Jan 26, 2025

#21767 closes all 3 above and this one.
It is ready for core review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

1 participant