Add str.format_map(mapping, /)
Merged
GA
2d ago+169+169+012345678901234567890123456789-34-34-01234567890123456789
Implements str.format_map(mapping, /) on str.
- Extends
FormatArgumentsincrates/monty/src/str_format.rswith aMapping(Value)variant sostr.format_map()reuses the existing PEP 3101 format string parser, conversions, nested format specs, attribute/item accesses, and resource-limit checks while delegating named root field lookups directly tomapping.py_getitem(key, vm). - Supports
dict,collections.defaultdict,collections.Counter, and user-defined mappings implementing__getitem__. - Rejects positional fields (
{},{0}, etc.) withValueError: Format string contains positional fieldsand validates the single positional-onlymappingargument. - Updates
docs/limitations/format.md.
Summary by cubic
Implements str.format_map(mapping, /), which previously raised AttributeError. It reuses the existing PEP 3101 format string parser from str.format(), so conversions, nested format specs, attribute/item access, and resource-limit checks work identically, but named root field lookups delegate to mapping.__getitem__.
- Supports
dict,defaultdict,Counter, and any user-defined mapping with__getitem__. - Positional fields (
{},{0}) raiseValueError: Format string contains positional fields, matching CPython. - The
mappingargument is positional-only and validated to accept exactly one argument with no kwargs. - Removes the
str.format_map()limitation from the docs and adds a test case file.