Petri Lehtinen <[email protected]> added the comment:
> PEP 3101 defines format strings as intermingled character data and markup.
> Markup defines replacement fields and is delimited by braces. Only after
> markup is extracted does the PEP talk about interpreting the contents of the
> markup.
>
> So, given "{0[a}b]}" the parser first parses out the character data and the
> markup. The first piece of markup is "{0[a}". That gives a syntax error
> because it's missing a right bracket.
>
> I realize you'd like the parser to find the markup as the entire string, but
> that's not how I read the PEP.
This is a good point, although the support of further replacement
fields inside format_specifiers requies the parser to count matching
braces, if the markup is to be extracted before its interpreted.
But disallowing unmathced '}' inside the replacement field doesn't
still explain why this shouldn't work:
'{0[!]!r}'.format({'!': 'foo'})
I'm completely fine with disallowing '}', but it seems to me that
there's absolutely no reason to not parse the element_index and later
fields correctly with respect to '!' and ':'.
----------
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue12014>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com