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-bugAn unexpected behavior, bug, or error
    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
    stdlibStandard Library Python modules in the Lib/ directory
    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

    stdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions