[formatter] allow dots etc in '…' literals (#5539)

don't parse fields starting with '

this disables the ability to directly apply […] to '…' literals,
but that's not really useful anyway and can still be done with _lit
This commit is contained in:
Mike Fährmann
2024-05-02 17:24:59 +02:00
parent 619bf5c644
commit d0cead105b
2 changed files with 22 additions and 12 deletions

View File

@@ -243,13 +243,12 @@ class TemplateFStringFormatter(FStringFormatter):
def parse_field_name(field_name):
if field_name[0] == "'":
return "_lit", (operator.itemgetter(field_name[1:-1]),)
first, rest = _string.formatter_field_name_split(field_name)
funcs = []
if first[0] == "'":
funcs.append(operator.itemgetter(first[1:-1]))
first = "_lit"
for is_attr, key in rest:
if is_attr:
func = operator.attrgetter