On Tue, Oct 20, 2020 at 8:41 PM Chris Angelico <ros...@gmail.com> wrote:

> >> f"{spam:d} {eggs:d} {cheese:d}" = "123 456"
> >
> > Wow! That sure looks like a strong anti-pattern.
> >
> > If some variable was assigned somewhere very distant in the program
> flow, a parser might succeed where it would otherwise fail!  It's not
> technically spooky action at a distance, but it's troublingly close.
>
> Not sure what you mean. It either succeeds or fails based on the string
> it's given, but if it succeeds, it assigns only those that match. So if you
> want some or all of them to have default values, you assign them
> beforehand.


So in your idea, after the above line runs, `cheese` will remain
undefined?! That's a different anti-pattern than the one I thought, but
equally bad.

Notice that is a HUGE asymmetry with regular unpacking.  I can never run:

a, b, c = some_expression

And wind up with a and b defined, but silently continue the program with c
undefined.

In your idea, is it the case that a line like yours above can simply NEVER
fail, in the sense of raising exceptions?  So maybe it runs and nothing is
actually bound?! I hate that even more than what I previously thought the
idea was.

> Just to repeat, a "scanf-string" just cannot be the same thing as an
> f-string.  Here is a perfectly good f-string, similar to ones I use all the
> time:
> > f"More than foo is {foo+1}"
> > There's just no way to make f-strings into an assignment target... what
> is POSSIBLE is making "some subset of f-strings (yet to be precisely
> specified)" patterns for a scan.
>
> Scanning and printing are not the same. This has been repeated many times,
> yet STILL people object on the basis that they won't be the same.
>

Well, "formatting" more generally, not only printing.  But the fact they
are different is EXACTLY the point I have tried to make a number of times.
Trying to shoe-horn a "formatting string" into a role of a "scanning
string" is exactly the problem.  They are NOT the same.

As I say, developing a "scanning mini-language" that is *inspired by* the
formatting language sounds great.  Trying to make the actual f-string do
double-duty as a scanning mini-language is a terrible idea.  That way lies
Perl.

It really does! Imagine trying to explain "What is an f-string?" in Python
3.11 under the proposal (I'm not sure which version is actually proposed,
but under any of them).  The answer becomes "Depending on context, the
meaning and interpretation of the symbols is one of these several things."
For the most part, Python tries hard to avoid "context sensitive grammar."
(Yes, I know exceptions, modulo is definitely different from string
interpolation, for example... although grammatically it's actually not,
just an operator that does very different things with strings versus
numbers).

-- 
The dead increasingly dominate and strangle both the living and the
not-yet born.  Vampiric capital and undead corporate persons abuse
the lives and control the thoughts of homo faber. Ideas, once born,
become abortifacients against new conceptions.
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/PY7MBO3PG2WZFUDNANF6SKPDWC4U26IM/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to