On Fri, Sep 18, 2020, 8:44 AM Eric V. Smith <eric@trueblade.com> wrote:


On 9/18/2020 8:19 AM, Ricky Teachey wrote:
On Fri, Sep 18, 2020, 8:17 AM Ricky Teachey <ricky@teachey.org> wrote:

Why not just grow a parse method on str that returns a dict and do it this way?

q = "{a} {b}"
p = "1 2"
(a, b) = q.parse(p)

Sorry that should have been:

(a, b) = q.parse(p).values()

I don't understand why returning a dict is useful. Unless this becomes as complicated as regexes with grouping, etc. (in which case: use a regex), the values will be returned in the order they appear in the template string. So just have it return a tuple:

a, b = q.parse(p)

Or for something that could be written today:

a, b = parse("{:d} {:d}", "1 2")
assert a == 1 and b == 2

I don't see the need for new syntax or new ways to assign values. You're not even removing any duplication compared to:

f"{a:d} {b:d}" = "1 2"

The larger point I'm really making is that adding parsing support of this kind to the language is a topic that needs to stand on its own without special f string magical syntax. regardless of how it's spelled, whether it's a parse function or a parse method or something else, that is what needs to be discussed first not magical syntax.