← 输入框|github.com|刷新
Skip to content

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

Closed

Description

@dg-pb

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

Activity

  1. added
    type-bug
    on Jan 25, 2025
  2. dg-pb commented on Jan 25, 2025

    @dg-pb
    ContributorAuthor

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

  3. dg-pb commented on Jan 25, 2025

    @dg-pb
    ContributorAuthor
  4. dg-pb commented on Jan 26, 2025

    @dg-pb
    ContributorAuthor

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

  5. added
    stdlib
    on Jan 27, 2025
  6. dg-pb commented on Jan 31, 2025

    @dg-pb
    ContributorAuthor

    Fixed by: #21767

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibtype-bug

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions