Mailing List Archive

PEP 622: capturing into an explicit namespace
Hi Python-dev and PEP 622 Authors,

I saw this idea, or something like it, posted by a couple of people, but
didn't see much discussion of it, and skimming the PEP today, I didn't see
a mention of it. Maybe I just missed it; my apologies if so, and a link to
the relevant discussion/text would be appreciated.

In any case, the basic idea was to have an explicit namespace that captures
are put into, and is treated as assignment instead of lookup. e.g.

match get_point() into m:
case Point(m.x, m.y):
print(m.x, m.y)
...etc...

A variation I saw was "as" instead of "into"; the particular token is
bikeshedding. The core idea is an explicit name that is "special" within
the match's case expressions.

Personally, I thought this was a rather elegant solution to the
load-vs-store problem for names. This is because, essentially, it changes
the mental model from "some non-dotted names are special, some aren't, keep
a careful eye out" to "only "m." is special, everything else is regular".

I haven't thought about this too deeply (analysis tools might benefit,
too?); I wanted to keep this initial email short before investing
time/energy/thought into it in case it had already been discussed and
discarded.
Re: PEP 622: capturing into an explicit namespace [ In reply to ]
On 18/07/20 4:34 am, Richard Levasseur wrote:
> match get_point() into m:
>   case Point(m.x, m.y):
>     print(m.x, m.y)
>   ...etc...
>
> Personally, I thought this was a rather elegant solution to the
> load-vs-store problem for names. This is because, essentially, it
> changes the mental model from "some non-dotted names are special, some
> aren't, keep a careful eye out" to "only "m." is special, everything
> else is regular".

This is a variant of "mark the assignments, not the values", but
with the marking done in a somewhat subtle way that can potentially
change from one match statement to another. I have trouble seeing
this as an improvement over just picking a character to use for
the marking.

--
Greg
_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-leave@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at https://mail.python.org/archives/list/python-dev@python.org/message/G2LOCBWEKHRH3PCUXDQFOBRJIZCVPTYW/
Code of Conduct: http://python.org/psf/codeofconduct/