[Python-ideas] Re: f-strings as assignment targets

2020-10-23 Thread Steven D'Aprano
On Fri, Oct 23, 2020 at 02:23:58AM -0400, David Mertz wrote: > See my very detailed posts on EXACTLY the concepts you discuss. > > "whether 'bar' is a name"? It is definitely a name, what you have no means > > to know is whether it has been assigned a value. I suspect you're trying to > > do the

[Python-ideas] Re: f-strings as assignment targets

2020-10-23 Thread David Mertz
See my very detailed posts on EXACTLY the concepts you discuss. "whether 'bar' is a name"? It is definitely a name, what you have no means > to know is whether it has been assigned a value. I suspect you're trying to > do the thing some people do where they insist on 'name' to avoid using the >

[Python-ideas] Re: f-strings as assignment targets

2020-10-22 Thread Random832
On Tue, Oct 20, 2020, at 22:03, David Mertz wrote: > My initial impression of your intent was: > > foo, bar = 42, 99 > # ... a million lines ... > line = "123/" > # ... more lines ... > f"{foo}/{bar}" = line > # raises if bar wasn't previously set > # binds to prior value if it was set > > But I

[Python-ideas] Re: f-strings as assignment targets

2020-10-22 Thread Eric V. Smith
On 10/22/2020 11:04 AM, Guido van Rossum wrote:  Another way this could go: If PEP 634 (pattern matching, reborn) gets accepted, a future Python version could add f-string patterns (which the PEP currently forbids). E.g. ``` x = "123 456 789" match x:   case f"{a} {b}": print("A pair:", a, b)  

[Python-ideas] Re: f-strings as assignment targets

2020-10-22 Thread Guido van Rossum
Another way this could go: If PEP 634 (pattern matching, reborn) gets accepted, a future Python version could add f-string patterns (which the PEP currently forbids). E.g. ``` x = "123 456 789" match x: case f"{a} {b}": print("A pair:", a, b) case f"{a} {b} {c}": print("Triple", a, b, c) ```

[Python-ideas] Re: f-strings as assignment targets

2020-10-22 Thread Eric V. Smith
On 10/22/2020 10:15 AM, Chris Angelico wrote: On Fri, Oct 23, 2020 at 1:11 AM Eric V. Smith wrote: And if all f-strings brought to the table was the ability to use simple variables as the value to be formatted, I'd have been opposed to that as well. What's the point of: f"{a} {b} {c}" when:

[Python-ideas] Re: f-strings as assignment targets

2020-10-22 Thread Chris Angelico
On Fri, Oct 23, 2020 at 1:11 AM Eric V. Smith wrote: > And if all f-strings brought to the table was the ability to use simple > variables as the value to be formatted, I'd have been opposed to that as > well. What's the point of: > > f"{a} {b} {c}" > > when: > > "{} {} {}".format(a, b, c) > >

[Python-ideas] Re: f-strings as assignment targets

2020-10-22 Thread Eric V. Smith
On 10/22/2020 5:21 AM, Steven D'Aprano wrote: On Wed, Oct 21, 2020 at 07:17:21PM -0700, Guido van Rossum wrote: Hmm, if the above is acceptable, maybe f-strings are still the logical next step, since they bring the format and the target name together again. That's not the only way to bring

[Python-ideas] Re: f-strings as assignment targets

2020-10-22 Thread Chris Angelico
On Fri, Oct 23, 2020 at 12:56 AM Paul Moore wrote: > > On Thu, 22 Oct 2020 at 14:44, Chris Angelico wrote: > > Returning a dict > > would be FAR less convenient for the most common cases, but as you > > say, it'd be the fallback for when you need dynamic parsing. > > If you're that sure that

[Python-ideas] Re: f-strings as assignment targets

2020-10-22 Thread Paul Moore
On Thu, 22 Oct 2020 at 14:44, Chris Angelico wrote: > Returning a dict > would be FAR less convenient for the most common cases, but as you > say, it'd be the fallback for when you need dynamic parsing. If you're that sure that direct assignment to locals would be a killer feature (I'm not, but

[Python-ideas] Re: f-strings as assignment targets

2020-10-22 Thread Chris Angelico
On Fri, Oct 23, 2020 at 12:31 AM Eric V. Smith wrote: > > On 10/22/2020 8:29 AM, Chris Angelico wrote: > > On Thu, Oct 22, 2020 at 8:22 PM Steven D'Aprano wrote: > >> Another problem is that using only a literal/display form as a target > >> means you can't pre-assemble a pattern and apply it

[Python-ideas] Re: f-strings as assignment targets

2020-10-22 Thread Eric V. Smith
On 10/22/2020 8:29 AM, Chris Angelico wrote: On Thu, Oct 22, 2020 at 8:22 PM Steven D'Aprano wrote: Another problem is that using only a literal/display form as a target means you can't pre-assemble a pattern and apply it later: # Match only the given domain. domain =

[Python-ideas] Re: f-strings as assignment targets

2020-10-22 Thread Paul Moore
On Thu, 22 Oct 2020 at 13:36, Chris Angelico wrote: > > On Thu, Oct 22, 2020 at 8:22 PM Steven D'Aprano wrote: > > > > On Wed, Oct 21, 2020 at 07:17:21PM -0700, Guido van Rossum wrote: > > > > > Hmm, if the above is acceptable, maybe f-strings are still the logical > > > next > > > step, since

[Python-ideas] Re: f-strings as assignment targets

2020-10-22 Thread Chris Angelico
On Thu, Oct 22, 2020 at 8:22 PM Steven D'Aprano wrote: > > On Wed, Oct 21, 2020 at 07:17:21PM -0700, Guido van Rossum wrote: > > > Hmm, if the above is acceptable, maybe f-strings are still the logical next > > step, since they bring the format and the target name together again. > > That's not

[Python-ideas] Re: f-strings as assignment targets

2020-10-22 Thread MRAB
On 2020-10-22 08:50, M.-A. Lemburg wrote: On 22.10.2020 04:12, David Mertz wrote: To bring it back to a concrete idea, here's how I see things: 1. The idea of f-string-like assignment targets has little support.  Only Chris, and maybe the OP who seems to have gone away. 2. The idea of a

[Python-ideas] Re: f-strings as assignment targets

2020-10-22 Thread Steven D'Aprano
On Wed, Oct 21, 2020 at 07:17:21PM -0700, Guido van Rossum wrote: > Hmm, if the above is acceptable, maybe f-strings are still the logical next > step, since they bring the format and the target name together again. That's not the only way to bring the format and target name together. Both

[Python-ideas] Re: f-strings as assignment targets

2020-10-22 Thread M.-A. Lemburg
On 22.10.2020 04:12, David Mertz wrote: > To bring it back to a concrete idea, here's how I see things: > > 1. The idea of f-string-like assignment targets has little support.  Only > Chris, and maybe the OP who seems to have gone away. > 2. The idea of a "scanning language" seems to garner

[Python-ideas] Re: f-strings as assignment targets

2020-10-22 Thread Paul Moore
On Thu, 22 Oct 2020 at 03:16, David Mertz wrote: > > To bring it back to a concrete idea, here's how I see things: > > The idea of f-string-like assignment targets has little support. Only Chris, > and maybe the OP who seems to have gone away. > The idea of a "scanning language" seems to garner

[Python-ideas] Re: f-strings as assignment targets

2020-10-21 Thread David Mertz
On Thu, Oct 22, 2020 at 4:17 AM Guido van Rossum wrote: > In terms of API, assuming functions, I think there are two basic models. > We could have two (or more) functions that were related though: >> >> # E.g. pat_with_names = "{foo:f}/{bar:4s}/{baz:3d}" >> matches = scan_to_obj(pat_with_names,

[Python-ideas] Re: f-strings as assignment targets

2020-10-21 Thread Guido van Rossum
On Wed, Oct 21, 2020 at 7:12 PM David Mertz wrote: > To bring it back to a concrete idea, here's how I see things: > >1. The idea of f-string-like assignment targets has little support. >Only Chris, and maybe the OP who seems to have gone away. >2. The idea of a "scanning language"

[Python-ideas] Re: f-strings as assignment targets

2020-10-21 Thread David Mertz
To bring it back to a concrete idea, here's how I see things: 1. The idea of f-string-like assignment targets has little support. Only Chris, and maybe the OP who seems to have gone away. 2. The idea of a "scanning language" seems to garner a fair amount of enthusiasm from everyone

[Python-ideas] Re: f-strings as assignment targets

2020-10-21 Thread Guido van Rossum
If I was the list moderator, at this point I would put the thread on a "cooling off" timeout for 8-16 hours. Both of you seem to be mainly complaining about each other's interaction style rather than adding anything of substance. Then again neither am I so why am I even writing this. :-) On Wed,

[Python-ideas] Re: f-strings as assignment targets

2020-10-21 Thread Chris Angelico
On Thu, Oct 22, 2020 at 10:36 AM Steven D'Aprano wrote: > > On Wed, Oct 21, 2020 at 12:16:16PM +1100, Chris Angelico wrote: > > > Please explain how it's "spooky action at a distance" if it's a > > self-contained assignment statement? > > "Spooky action at a distance" is your phrase, not mine, or

[Python-ideas] Re: f-strings as assignment targets

2020-10-21 Thread Steven D'Aprano
On Wed, Oct 21, 2020 at 12:16:16PM +1100, Chris Angelico wrote: > Please explain how it's "spooky action at a distance" if it's a > self-contained assignment statement? "Spooky action at a distance" is your phrase, not mine, or Rob's. (I think David Mertz may have used it first, but I don't

[Python-ideas] Re: f-strings as assignment targets

2020-10-21 Thread David Mertz
On Wed, Oct 21, 2020, 7:21 PM Steven D'Aprano > There's a middle ground of text parsing tasks that would seem to be a good > match for some sort of scanner, inspired by C's scanf, whether it uses % or > {} format codes. > Maybe COBOL PICTURE clauses. Admittedly, I've never used COBOL, but I

[Python-ideas] Re: f-strings as assignment targets

2020-10-21 Thread Steven D'Aprano
On Wed, Oct 21, 2020 at 11:07:28AM -0700, Christopher Barker wrote: > As for the question of do we need a scanning language at all? We already > have pretty full features string methods, and regex for the complex stuff. > > I think yes -- for both simplicity for the simple stuff (the easy stuff

[Python-ideas] Re: f-strings as assignment targets

2020-10-21 Thread Christopher Barker
On Tue, Oct 20, 2020 at 12:14 PM David Mertz wrote: > 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

[Python-ideas] Re: f-strings as assignment targets

2020-10-20 Thread David Mertz
On Wed, Oct 21, 2020, 12:12 AM Chris Angelico > > But I think what you want is for the binding line never to raise, but > also not to have any local means to know whether 'bar' is a name after that > line. Or whether 'foo' is, for that matter. > > Easy: it always is. Whether it has had a value

[Python-ideas] Re: f-strings as assignment targets

2020-10-20 Thread Chris Angelico
On Wed, Oct 21, 2020 at 1:03 PM David Mertz wrote: > > On Tue, Oct 20, 2020, 9:17 PM Chris Angelico >> >> Please explain how it's "spooky action at a distance" if it's a >> self-contained assignment statement? > > > I'm not Steven, but I think I'm the first one in the thread to use Einstein's >

[Python-ideas] Re: f-strings as assignment targets

2020-10-20 Thread David Mertz
On Tue, Oct 20, 2020, 9:17 PM Chris Angelico > Please explain how it's "spooky action at a distance" if it's a > self-contained assignment statement? > I'm not Steven, but I think I'm the first one in the thread to use Einstein's phrase. As I understand your current semantics, that phrase is not

[Python-ideas] Re: f-strings as assignment targets

2020-10-20 Thread Chris Angelico
On Wed, Oct 21, 2020 at 12:08 PM Steven D'Aprano wrote: > > On Wed, Oct 21, 2020 at 10:49:41AM +1100, Chris Angelico wrote: > > On Wed, Oct 21, 2020 at 10:39 AM Steven D'Aprano > > wrote: > > > > The > > > > f-string has to be a literal - it's not a magic object that you can > > > > assign to

[Python-ideas] Re: f-strings as assignment targets

2020-10-20 Thread Steven D'Aprano
On Wed, Oct 21, 2020 at 10:49:41AM +1100, Chris Angelico wrote: > On Wed, Oct 21, 2020 at 10:39 AM Steven D'Aprano wrote: > > > The > > > f-string has to be a literal - it's not a magic object that you can > > > assign to and new locals appear. > > > > Well, no, it's not an object at all, but

[Python-ideas] Re: f-strings as assignment targets

2020-10-20 Thread Eric V. Smith
On 10/20/2020 7:38 PM, Steven D'Aprano wrote: On Wed, Oct 21, 2020 at 02:15:40AM +1100, Chris Angelico wrote: or even: f"{acc},{date},{type},{amount:[0-9.]} {description},{refnum:12s}{reference}" = line At the point you have something that complicated, I think that existing solutions with

[Python-ideas] Re: f-strings as assignment targets

2020-10-20 Thread David Mertz
On Wed, Oct 21, 2020 at 1:22 AM Steven D'Aprano wrote: > I think we have at least six mini-languages now? > - regexes > - string interpolation with % > - template strings > - format mini-language > - f-strings > - date/time format strings > We also have the struct mini-language for interpreting

[Python-ideas] Re: f-strings as assignment targets

2020-10-20 Thread Chris Angelico
On Wed, Oct 21, 2020 at 10:22 AM Steven D'Aprano wrote: > > Well... yes. And oddly enough, developing a scanning mini-language > > inspired by the formatting language is *exactly* what this proposal > > is, and has always been. > > That's incorrect. > > The first post in this thread: > >

[Python-ideas] Re: f-strings as assignment targets

2020-10-20 Thread Chris Angelico
On Wed, Oct 21, 2020 at 10:39 AM Steven D'Aprano wrote: > > The > > f-string has to be a literal - it's not a magic object that you can > > assign to and new locals appear. > > Well, no, it's not an object at all, but surely "you can assign to and > new locals appear" is the whole point of the

[Python-ideas] Re: f-strings as assignment targets

2020-10-20 Thread Steven D'Aprano
On Wed, Oct 21, 2020 at 02:15:40AM +1100, Chris Angelico wrote: > On Tue, Oct 20, 2020 at 11:54 PM Steven D'Aprano wrote: > > The only advantage, I guess, of f-string like syntax is that the > > variable names can be embedded inside the template string: > > > > f"{path:s} - {errors:d} errors,

[Python-ideas] Re: f-strings as assignment targets

2020-10-20 Thread Steven D'Aprano
On Wed, Oct 21, 2020 at 06:17:27AM +1100, Chris Angelico wrote: > No; it can fail if the pattern actually rejects it. For instance, a > pattern of "a{x}b{y}c" can match the string "a" but won't assign to y, It won't assign to x either, if I'm understanding it correctly, since there is nothing

[Python-ideas] Re: f-strings as assignment targets

2020-10-20 Thread Chris Angelico
On Wed, Oct 21, 2020 at 6:06 AM David Mertz wrote: > > On Tue, Oct 20, 2020 at 8:41 PM Chris Angelico 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

[Python-ideas] Re: f-strings as assignment targets

2020-10-20 Thread David Mertz
On Tue, Oct 20, 2020 at 8:41 PM Chris Angelico 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

[Python-ideas] Re: f-strings as assignment targets

2020-10-20 Thread Chris Angelico
On Wed, Oct 21, 2020 at 5:07 AM David Mertz wrote: > > On Tue, Oct 20, 2020 at 6:20 PM Chris Angelico wrote: >> >> spam = eggs = cheese = None >> 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

[Python-ideas] Re: f-strings as assignment targets

2020-10-20 Thread David Mertz
On Tue, Oct 20, 2020 at 6:20 PM Chris Angelico wrote: > spam = eggs = cheese = None > 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

[Python-ideas] Re: f-strings as assignment targets

2020-10-20 Thread Chris Angelico
On Wed, Oct 21, 2020 at 3:46 AM Steven D'Aprano wrote: > > On Wed, Oct 21, 2020 at 03:19:20AM +1100, Chris Angelico wrote: > > > In every sscanf-like system I've used, there is a default value of > > some sort, either because variables are automatically initialized, or > > because the sscanf

[Python-ideas] Re: f-strings as assignment targets

2020-10-20 Thread Steven D'Aprano
On Wed, Oct 21, 2020 at 03:19:20AM +1100, Chris Angelico wrote: > In every sscanf-like system I've used, there is a default value of > some sort, either because variables are automatically initialized, or > because the sscanf construct itself provides a default. Then it won't go "Boom!" as you

[Python-ideas] Re: f-strings as assignment targets

2020-10-20 Thread Chris Angelico
On Wed, Oct 21, 2020 at 3:04 AM Steven D'Aprano wrote: > > That leads to > > an all-or-nothing result for the simple form, and no easy way to do > > anything else. Consider: > > > > a, b, c = sscanf("%d %d %d", "123 432") > > > > Boom! Instead of having a clean way to represent partial parsing. >

[Python-ideas] Re: f-strings as assignment targets

2020-10-20 Thread Paul Moore
On Tue, 20 Oct 2020 at 17:04, Steven D'Aprano wrote: > > In general, Python bindings are *all or nothing* -- either all the > targets get bound, or none of them. I wonder if this could work with the proposed pattern matching statement. The current proposal doesn't allow it, but maybe a future

[Python-ideas] Re: f-strings as assignment targets

2020-10-20 Thread Steven D'Aprano
On Wed, Oct 21, 2020 at 02:18:49AM +1100, Chris Angelico wrote: > > Er, well, why not just add a sscanf to Python? > > A couple of reasons, but the main one is that you can't have "output > variables" (in C, sscanf takes pointers, so you pass it the address of > your variables), which means that

[Python-ideas] Re: f-strings as assignment targets

2020-10-20 Thread Chris Angelico
On Wed, Oct 21, 2020 at 1:13 AM Rob Cliffe wrote: > > On 20/10/2020 13:05, Chris Angelico wrote: > > On Tue, Oct 20, 2020 at 10:37 PM Rob Cliffe via Python-ideas > > wrote: > >> In short, "assigning" to f-strings is not and cannot be a simple reversal > >> of having them in expressions.

[Python-ideas] Re: f-strings as assignment targets

2020-10-20 Thread Chris Angelico
On Tue, Oct 20, 2020 at 11:54 PM Steven D'Aprano wrote: > The only advantage, I guess, of f-string like syntax is that the > variable names can be embedded inside the template string: > > f"{path:s} - {errors:d} errors, {%warnings:d}" = line > > but I'm not convinced that's actually an

[Python-ideas] Re: f-strings as assignment targets

2020-10-20 Thread Steven D'Aprano
On Sun, Sep 20, 2020 at 03:59:40AM +0100, Rob Cliffe via Python-ideas wrote: > -1 on the whole proposal. I agree with the negative on this proposal. I don't think that f-strings are a good fit for this, and I'm not sure that we need syntax for something that could be handled by a function

[Python-ideas] Re: f-strings as assignment targets

2020-10-20 Thread Chris Angelico
On Tue, Oct 20, 2020 at 10:37 PM Rob Cliffe via Python-ideas wrote: > In short, "assigning" to f-strings is not and cannot be a simple reversal of > having them in expressions. Rather, it is opening a big can of worms. > It's not a reversal of them being in expressions any more than assigning

[Python-ideas] Re: f-strings as assignment targets

2020-10-20 Thread Rob Cliffe via Python-ideas
-1 on the whole proposal. Currently when I see an f-string such as     f"My name is {name} and my age is {age}." I can easily translate it mentally (if I have to - usually I don't) into     "My name is " + str(name) + " and my age is " + str(age) + "." Whether such a translation is technically

[Python-ideas] Re: f-strings as assignment targets

2020-09-21 Thread Christopher Barker
On Sun, Sep 20, 2020 at 2:27 AM Stephen J. Turnbull < turnbull.stephen...@u.tsukuba.ac.jp> wrote: > Are you sure that shouldn't be "I was told to expect three things, but > I found six?" ;-) > > And why not parse a_string using the "grammar" "{x}{y}{z}" as {'x': > 2345, 'y': 6, 'z': 7}? That's

[Python-ideas] Re: f-strings as assignment targets

2020-09-20 Thread Wes Turner
Parsing ... Parsing natural language (s) with and without Context-Free Grammars https://en.wikipedia.org/wiki/Parsing https://en. wikipedia.org/wiki/Natural_language_processing https://en.wikipedia.org/wiki/Context-free_grammar#Undecidable_problems (*) ### NLTK

[Python-ideas] Re: f-strings as assignment targets

2020-09-20 Thread Greg Ewing
On 20/09/20 9:25 pm, Stephen J. Turnbull wrote: Are you sure that shouldn't be "I was told to expect three things, but I found six?" ;-) And why not parse a_string using the "grammar" "{x}{y}{z}" as {'x': 2345, 'y': 6, 'z': 7}? As a human I tend to expect input formats to be somewhat sensible

[Python-ideas] Re: f-strings as assignment targets

2020-09-20 Thread Wes Turner
Tests for parsers / [regex] pattern matchers in the CPython standard library: https://github.com/python/cpython/blob/master/Lib/test/test_fstring.py https://github.com/python/cpython/blob/master/Lib/test/re_tests.py https://github.com/python/cpython/blob/master/Lib/test/test_re.py

[Python-ideas] Re: f-strings as assignment targets

2020-09-20 Thread Stephen J. Turnbull
Greg Ewing writes: > On 20/09/20 7:45 am, Christopher Barker wrote: > > In [4]: from parse import parse > > In [5]: parse("{x}{y}{z}", a_string) > > Out[5]: > > > > In [6]: parse("{x:d}{y:d}{z:d}", a_string) > > Out[6]: > > > > So that's interesting -- different level of "greadiness"

[Python-ideas] Re: f-strings as assignment targets

2020-09-19 Thread Christopher Barker
On Sat, Sep 19, 2020 at 4:46 PM Greg Ewing wrote: > On 20/09/20 7:45 am, Christopher Barker wrote: > > In [4]: from parse import parse > > In [5]: parse("{x}{y}{z}", a_string) > > Out[5]: > > > > In [6]: parse("{x:d}{y:d}{z:d}", a_string) > > Out[6]: > > > > So that's interesting -- different

[Python-ideas] Re: f-strings as assignment targets

2020-09-19 Thread Greg Ewing
On 20/09/20 7:45 am, Christopher Barker wrote: In [4]: from parse import parse In [5]: parse("{x}{y}{z}", a_string) Out[5]: In [6]: parse("{x:d}{y:d}{z:d}", a_string) Out[6]: So that's interesting -- different level of "greadiness" for strings than integers Hmmm, that seems really

[Python-ideas] Re: f-strings as assignment targets

2020-09-19 Thread Ricky Teachey
+1 on adding something like parse to the language. -0 on the assignment feature... it just doesn't seem to be that beneficial to me. But once parse exists in the language a rational and limited conversation about the fstring assignment feature becomes much more possible. On Sat, Sep 19, 2020,

[Python-ideas] Re: f-strings as assignment targets

2020-09-19 Thread Christopher Barker
On Sat, Sep 19, 2020 at 12:10 PM Wes Turner wrote: > Regex uses the ? symbol to indicate that something is a "non-greedy" match > (to default to "shortest match") > exactly -- Regex was designed to be a parsing language, format specifiers were not. I'm quite surprised by how little the parse

[Python-ideas] Re: f-strings as assignment targets

2020-09-19 Thread Wes Turner
Regex uses the ? symbol to indicate that something is a "non-greedy" match (to default to "shortest match") import re str_ = "a:b:c" assert re.match(r'(.*):(.*)', str_).groups() == ("a:b", "c") assert re.match(r'(.*?):(.*)', str_).groups() == ("a", "b:c") Typically, debugging parsing issues

[Python-ideas] Re: f-strings as assignment targets

2020-09-19 Thread Rob Cliffe via Python-ideas
Parsing can be ambiguous:     f"{x}:{y}" = "a:b:c" Does this set     x = "a"     y = "b:c" or     x = "a:b"     y = "c" Rob Cliffe On 17/09/2020 05:52, Dennis Sweeney wrote: TL;DR: I propose the following behavior: >>> s = "She turned me into a newt." >>> f"She turned me into a

[Python-ideas] Re: f-strings as assignment targets

2020-09-18 Thread Alex Hall
On Fri, Sep 18, 2020 at 4:56 AM Steven D'Aprano wrote: > But that's a *separate problem*. Regexes can't assign directly either. > And we wouldn't want them to! (It's okay for a regex to have it's own > internal namespace, like named groups, but it shouldn't leak out into > the locals or

[Python-ideas] Re: f-strings as assignment targets

2020-09-18 Thread Chris Angelico
On Sat, Sep 19, 2020 at 8:59 AM Dennis Sweeney wrote: > > I think it would be easiest to reason about if an Exception is always raised > when not everything is assigned to. Just like the behavior of other unpacking > assignment, either everything is assigned or there's an error. My apologies >

[Python-ideas] Re: f-strings as assignment targets

2020-09-18 Thread Dennis Sweeney
I think it would be easiest to reason about if an Exception is always raised when not everything is assigned to. Just like the behavior of other unpacking assignment, either everything is assigned or there's an error. My apologies if that wasn't clear from the examples.

[Python-ideas] Re: f-strings as assignment targets

2020-09-18 Thread David Mertz
On Fri, Sep 18, 2020, 2:22 AM Ricky Teachey > On Fri, Sep 18, 2020, 6:35 AM Alex Hall > >> The point is that this: >> > >> (a, b) = c >> >> is 'assigning to a literal' just as much as this: >> >> f"{a} {b}" = c >> >> Both are just things that look like expressions with dynamic values but

[Python-ideas] Re: f-strings as assignment targets

2020-09-18 Thread Ricky Teachey
On Fri, Sep 18, 2020 at 12:16 PM Wes Turner wrote: > This functionality MUST be accessible with a function or a method. (?) > > As already mentioned, building up a pattern string and then using that on > the LHS cannot work: > > >>> pattern = "{a:d} {b:d}" > >>> pattern += " {c:s}" > >>>

[Python-ideas] Re: f-strings as assignment targets

2020-09-18 Thread Wes Turner
This functionality MUST be accessible with a function or a method. (?) As already mentioned, building up a pattern string and then using that on the LHS cannot work: >>> pattern = "{a:d} {b:d}" >>> pattern += " {c:s}" >>> pattern = "12 34 ef" This is the way Parse works; you call parse()

[Python-ideas] Re: f-strings as assignment targets

2020-09-18 Thread Ricky Teachey
On Fri, Sep 18, 2020, 9:16 AM Chris Angelico wrote: > On Fri, Sep 18, 2020 at 11:04 PM Ricky Teachey wrote: > > > > On Fri, Sep 18, 2020, 8:34 AM Chris Angelico wrote: > >> > >> On Fri, Sep 18, 2020 at 10:26 PM Ricky Teachey > wrote: > >> > > >> > On Fri, Sep 18, 2020, 8:17 AM Ricky Teachey

[Python-ideas] Re: f-strings as assignment targets

2020-09-18 Thread Chris Angelico
On Fri, Sep 18, 2020 at 11:04 PM Ricky Teachey wrote: > > On Fri, Sep 18, 2020, 8:34 AM Chris Angelico wrote: >> >> On Fri, Sep 18, 2020 at 10:26 PM Ricky Teachey wrote: >> > >> > On Fri, Sep 18, 2020, 8:17 AM Ricky Teachey wrote: >> >> >> >> >> >> Why not just grow a parse method on str that

[Python-ideas] Re: f-strings as assignment targets

2020-09-18 Thread Ricky Teachey
On Fri, Sep 18, 2020, 8:44 AM Eric V. Smith wrote: > > On 9/18/2020 8:19 AM, Ricky Teachey wrote: > > On Fri, Sep 18, 2020, 8:17 AM Ricky Teachey 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) =

[Python-ideas] Re: f-strings as assignment targets

2020-09-18 Thread Ricky Teachey
On Fri, Sep 18, 2020, 8:34 AM Chris Angelico wrote: > On Fri, Sep 18, 2020 at 10:26 PM Ricky Teachey wrote: > > > > On Fri, Sep 18, 2020, 8:17 AM Ricky Teachey wrote: > >> > >> > >> Why not just grow a parse method on str that returns a dict and do it > this way? > >> > >> > >> q = "{a} {b}" >

[Python-ideas] Re: f-strings as assignment targets

2020-09-18 Thread Eric V. Smith
On 9/18/2020 8:19 AM, Ricky Teachey wrote: On Fri, Sep 18, 2020, 8:17 AM Ricky Teachey > 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

[Python-ideas] Re: f-strings as assignment targets

2020-09-18 Thread Chris Angelico
On Fri, Sep 18, 2020 at 10:26 PM Ricky Teachey wrote: > > On Fri, Sep 18, 2020, 8:17 AM Ricky Teachey 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:

[Python-ideas] Re: f-strings as assignment targets

2020-09-18 Thread Ricky Teachey
On Fri, Sep 18, 2020, 8:17 AM Ricky Teachey 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()

[Python-ideas] Re: f-strings as assignment targets

2020-09-18 Thread Ricky Teachey
On Fri, Sep 18, 2020, 6:35 AM Alex Hall wrote: > The point is that this: > > (a, b) = c > > is 'assigning to a literal' just as much as this: > > f"{a} {b}" = c > > Both are just things that look like expressions with dynamic values but > aren't. > I agree with you. It's not that

[Python-ideas] Re: f-strings as assignment targets

2020-09-18 Thread Alex Hall
On Fri, Sep 18, 2020 at 3:46 AM Steven D'Aprano wrote: > If there is anything that might justify the name "tuple (or list) > literal" it would be a tuple with each item a literal: > > (1, "a", None) > > but certainly not one containing expressions or names: > > (spam+1, eggs(),

[Python-ideas] Re: f-strings as assignment targets

2020-09-17 Thread Brendan Barnwell
On 2020-09-17 12:16, Alex Hall wrote: On Thu, Sep 17, 2020 at 8:57 PM Brendan Barnwell mailto:brenb...@brenbarn.net>> wrote: On 2020-09-16 21:52, Dennis Sweeney wrote: > TL;DR: I propose the following behavior: > > >>> s = "She turned me into a newt." > >>>

[Python-ideas] Re: f-strings as assignment targets

2020-09-17 Thread Steven D'Aprano
On Fri, Sep 18, 2020 at 10:53:57AM +1000, Chris Angelico wrote: > On Fri, Sep 18, 2020 at 10:51 AM Steven D'Aprano wrote: > > > > On Thu, Sep 17, 2020 at 11:09:35PM +1000, Chris Angelico wrote: > > > > > I've frequently yearned for an sscanf-like feature in Python. Usually > > > I end up

[Python-ideas] Re: f-strings as assignment targets

2020-09-17 Thread Guido van Rossum
I think this is a feature in Scala. A friend showed me this example: ``` def splitDate(s: String) = s match { case s"$day-$month-$year" => s"day: $day, mon: $month, yr: $year" case _ => "not a date" } ``` Note that the example shows two sides of s-strings: the first one as a

[Python-ideas] Re: f-strings as assignment targets

2020-09-17 Thread David Mertz
On Thu, Sep 17, 2020, 4:30 PM Steven D'Aprano wrote: > On Thu, Sep 17, 2020 at 01:12:02PM -1000, David Mertz wrote: > > I did actually "write the book" on text processing in Python. I think > it's painful and awkward, and a terrible idea. > > *Text processing* is a terrible idea? > In for a

[Python-ideas] Re: f-strings as assignment targets

2020-09-17 Thread Steven D'Aprano
On Thu, Sep 17, 2020 at 01:12:02PM -1000, David Mertz wrote: > I did actually "write the book" on text processing in Python. I think it's > painful and awkward, and a terrible idea. *Text processing* is a terrible idea? Or hammering the square peg of scanf into the round hole of f-strings?

[Python-ideas] Re: f-strings as assignment targets

2020-09-17 Thread Chris Angelico
On Fri, Sep 18, 2020 at 12:15 PM David Mertz wrote: > > On Thu, Sep 17, 2020, 4:04 PM Chris Angelico >> >> > >>> my_string = "It might be 11:45 PM" >> > >>> # ... many lines later ... >> > >>> f"It is {hh}:{mm} {am_or_pm}" = my_string >> > >> > What are hh, mm, and am_or_pm now? Do we raise an

[Python-ideas] Re: f-strings as assignment targets

2020-09-17 Thread David Mertz
On Thu, Sep 17, 2020, 4:04 PM Chris Angelico > > >>> my_string = "It might be 11:45 PM" > > >>> # ... many lines later ... > > >>> f"It is {hh}:{mm} {am_or_pm}" = my_string > > > > What are hh, mm, and am_or_pm now? Do we raise an exception? Do we run > the line having no real idea whether they

[Python-ideas] Re: f-strings as assignment targets

2020-09-17 Thread Steven D'Aprano
On Thu, Sep 17, 2020 at 09:44:09PM +0200, Alex Hall wrote: > > The intent being: save the f-string as a variable, and then use it to > > assign later. But that can obviously never work because q would just become > > the string "1 2 3" . > > > > The same problem exists for assignments to tuples,

[Python-ideas] Re: f-strings as assignment targets

2020-09-17 Thread Chris Angelico
On Fri, Sep 18, 2020 at 11:51 AM David Mertz wrote: > > Let's try some others: > > >>> my_string = "It might be 11:45 PM" > >>> # ... many lines later ... > >>> f"It is {hh}:{mm} {am_or_pm}" = my_string > > What are hh, mm, and am_or_pm now? Do we raise an exception? Do we run the > line

[Python-ideas] Re: f-strings as assignment targets

2020-09-17 Thread David Mertz
On Thu, Sep 17, 2020 at 2:31 PM Dennis Sweeney wrote: > I was definitely not proposing "spooky action at a distance". My proposal > is to existing f-strings as the `__setattr__` protocol is to the > `__getattr__` protocol. The template would only ever be hard-coded inline > during the f-string

[Python-ideas] Re: f-strings as assignment targets

2020-09-17 Thread Steven D'Aprano
On Thu, Sep 17, 2020 at 09:16:46PM +0200, Alex Hall wrote: > On Thu, Sep 17, 2020 at 8:57 PM Brendan Barnwell > wrote: > > I don't like this at all. It looks like assigning to a literal, > > which > > is weird. > > > People keep saying this, but iterable unpacking looks like assigning

[Python-ideas] Re: f-strings as assignment targets

2020-09-17 Thread Wes Turner
That would require changes to all existing static analysis tools (again). On Thu, Sep 17, 2020 at 8:31 PM Dennis Sweeney wrote: > I was definitely not proposing "spooky action at a distance". My proposal > is to existing f-strings as the `__setattr__` protocol is to the > `__getattr__`

[Python-ideas] Re: f-strings as assignment targets

2020-09-17 Thread Chris Angelico
On Fri, Sep 18, 2020 at 10:51 AM Steven D'Aprano wrote: > > On Thu, Sep 17, 2020 at 11:09:35PM +1000, Chris Angelico wrote: > > > I've frequently yearned for an sscanf-like feature in Python. Usually > > I end up longhanding it with string methods, or else reaching for a > > regex, but neither of

[Python-ideas] Re: f-strings as assignment targets

2020-09-17 Thread Chris Angelico
On Fri, Sep 18, 2020 at 10:38 AM Steven D'Aprano wrote: > > On Fri, Sep 18, 2020 at 09:05:39AM +1000, Chris Angelico wrote: > > > > f-strings are not literals. They are a form of eval(). > > > > Oh, that makes 'em sound way too scary :) They're more akin to a list > > display - a syntactic

[Python-ideas] Re: f-strings as assignment targets

2020-09-17 Thread Ricky Teachey
On Thu, Sep 17, 2020 at 8:33 PM Dennis Sweeney wrote: > I was definitely not proposing "spooky action at a distance". My proposal > is to existing f-strings as the `__setattr__` protocol is to the > `__getattr__` protocol. The template would only ever be hard-coded inline > during the f-string

[Python-ideas] Re: f-strings as assignment targets

2020-09-17 Thread Steven D'Aprano
On Thu, Sep 17, 2020 at 11:09:35PM +1000, Chris Angelico wrote: > I've frequently yearned for an sscanf-like feature in Python. Usually > I end up longhanding it with string methods, or else reaching for a > regex, but neither of those is quite what I want. I'd prefer scanf > notation to format

[Python-ideas] Re: f-strings as assignment targets

2020-09-17 Thread Steven D'Aprano
On Fri, Sep 18, 2020 at 09:05:39AM +1000, Chris Angelico wrote: > > f-strings are not literals. They are a form of eval(). > > Oh, that makes 'em sound way too scary :) They're more akin to a list > display - a syntactic structure that yields a well-defined object, and > has expressions inside

[Python-ideas] Re: f-strings as assignment targets

2020-09-17 Thread Dennis Sweeney
I was definitely not proposing "spooky action at a distance". My proposal is to existing f-strings as the `__setattr__` protocol is to the `__getattr__` protocol. The template would only ever be hard-coded inline during the f-string assignment. This is the same restriction that existing

[Python-ideas] Re: f-strings as assignment targets

2020-09-17 Thread David Mertz
This library I like! It's very similar to the hypothetical 'template()' function I mention in my other email. But this doesn't mess with Python's model of assignment targets, names, etc. I haven't seen this before, but I want to play around with it. On Thu, Sep 17, 2020, 1:24 PM Wes Turner

[Python-ideas] Re: f-strings as assignment targets

2020-09-17 Thread Wes Turner
>From https://github.com/r1chardj0n3s/parse/blob/master/README.rst : ```rst Format Specification Most often a straight format-less ``{}`` will suffice where a more complex format specification might have been used. Most of `format()`'s `Format Specification Mini-Language`_

[Python-ideas] Re: f-strings as assignment targets

2020-09-17 Thread Wes Turner
f"It's not {regex:d{2}}" https://github.com/r1chardj0n3s/parse > Parse strings using a specification based on the Python format() syntax. On Thu, Sep 17, 2020 at 7:15 PM David Mertz wrote: > I did actually "write the book" on text processing in Python. I think it's > painful and awkward,

[Python-ideas] Re: f-strings as assignment targets

2020-09-17 Thread David Mertz
I did actually "write the book" on text processing in Python. I think it's painful and awkward, and a terrible idea. On Thu, Sep 17, 2020, 1:00 PM Chris Angelico wrote: > On Fri, Sep 18, 2020 at 8:54 AM Ben Rudiak-Gould > wrote: > > This is a terrible idea. > > Python is an excellent language

  1   2   >