[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-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] f-string: empty expression should be allowed

2020-10-22 Thread Hans Ginzel
Hello, consider this snippet please cursor.execute(f"INSERT INTO {table} VALUES (1, '{}');") SyntaxError: f-string: empty expression not allowed It is (absolutely) correct to insert empty json into database table field. Empty expression in f-string should * (silently) expand as '{}' (opening an

[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 brace

[Python-ideas] Re: f-string: empty expression should be allowed

2020-10-22 Thread Steven D'Aprano
On Thu, Oct 22, 2020 at 10:58:00AM +0200, Hans Ginzel wrote: > Hello, > > consider this snippet please > > cursor.execute(f"INSERT INTO {table} VALUES (1, '{}');") > SyntaxError: f-string: empty expression not allowed Escape the braces by doubling them: f"INSERT INTO {table} VALUES (1, '{{

[Python-ideas] Re: f-string: empty expression should be allowed

2020-10-22 Thread Hans Ginzel
On Thu, Oct 22, 2020 at 08:31:34PM +1100, Steven D'Aprano wrote: cursor.execute(f"INSERT INTO {table} VALUES (1, '{}');") SyntaxError: f-string: empty expression not allowed Escape the braces by doubling them: f"INSERT INTO {table} VALUES (1, '{{}}');" Thank you for (ugly) workaorund. Th

[Python-ideas] Re: f-string: empty expression should be allowed

2020-10-22 Thread Paul Moore
On Thu, 22 Oct 2020 at 11:39, Hans Ginzel wrote: > > On Thu, Oct 22, 2020 at 08:31:34PM +1100, Steven D'Aprano wrote: > >> cursor.execute(f"INSERT INTO {table} VALUES (1, '{}');") > >> SyntaxError: f-string: empty expression not allowed > > > >Escape the braces by doubling them: > >f"INSERT IN

[Python-ideas] Re: f-string: empty expression should be allowed

2020-10-22 Thread André Roberge
On Thu, Oct 22, 2020 at 7:39 AM Hans Ginzel wrote: > On Thu, Oct 22, 2020 at 08:31:34PM +1100, Steven D'Aprano wrote: > >> cursor.execute(f"INSERT INTO {table} VALUES (1, '{}');") > >> SyntaxError: f-string: empty expression not allowed > > > >Escape the braces by doubling them: > >f"INSERT I

[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-string: empty expression should be allowed

2020-10-22 Thread Eric V. Smith
On 10/22/2020 4:58 AM, Hans Ginzel wrote: Hello, consider this snippet please cursor.execute(f"INSERT INTO {table} VALUES (1, '{}');") SyntaxError: f-string: empty expression not allowed It is (absolutely) correct to insert empty json into database table field. Empty expression in f-string s

[Python-ideas] Re: f-string: empty expression should be allowed

2020-10-22 Thread Marco Sulla
On Thu, 22 Oct 2020 at 12:36, Hans Ginzel wrote: > On Thu, Oct 22, 2020 at 08:31:34PM +1100, Steven D'Aprano wrote: > >> cursor.execute(f"INSERT INTO {table} VALUES (1, '{}');") > >> SyntaxError: f-string: empty expression not allowed > > > >Escape the braces by doubling them: > >f"INSERT INT

[Python-ideas] Re: f-string: empty expression should be allowed

2020-10-22 Thread Chris Angelico
On Thu, Oct 22, 2020 at 8:12 PM Hans Ginzel wrote: > > Hello, > > consider this snippet please > > cursor.execute(f"INSERT INTO {table} VALUES (1, '{}');") > SyntaxError: f-string: empty expression not allowed > > It is (absolutely) correct to insert empty json into database table field. > Empty e

[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 th

[Python-ideas] Re: f-string: empty expression should be allowed

2020-10-22 Thread Hans Ginzel
On Thu, Oct 22, 2020 at 11:32:36PM +1100, Chris Angelico wrote: My recommendation here would be to separate the part where you insert a table name from the rest of the statement: cursor.execute(f"INSERT INTO {table} " "VALUES (1, '{}')") That way, you aren't at risk of SQL injection in the res

[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 t

[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 = get_wanted_doma

[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 lat

[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 y

[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 dire

[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 t

[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) > > doe

[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 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) ``` E

[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-string: empty expression should be allowed

2020-10-22 Thread Guido van Rossum
On Thu, Oct 22, 2020 at 3:37 AM Hans Ginzel wrote: > Thank you for (ugly) workaorund. > Careful who you're calling ugly. -- --Guido van Rossum (python.org/~guido) *Pronouns: he/him **(why is my pronoun here?)*

[Python-ideas] Re: Call a function at invocation

2020-10-22 Thread Michael Smith
What a few responders have said is along the lines that my proposal 1. Can already be done. 2. Has gaps/is too simple. I will try to address those points here, but before I start, I'm getting the impression I don't have a great grasp of the communication style of this list. I assumed that a simpl

[Python-ideas] Re: Call a function at invocation

2020-10-22 Thread David Mertz
I really don't see this goal as general purpose enough to merit Python syntax or standard library inclusion. Needing a PyPI package to do something slightly uncommon really doesn't feel like a bad obstacle. Click is perfectly great. It's a nice package for creating a certain kind of command lin

[Python-ideas] Re: f-string: empty expression should be allowed

2020-10-22 Thread Steven D'Aprano
On Thu, Oct 22, 2020 at 12:29:22PM +0200, Hans Ginzel wrote: > >We could do that, but this is more likely to just hide bugs in the > >f-string than be useful. > > Thank you, that would be great and useful. Oh, sorry Hans, I think that you may have misunderstood me. In English, "We could do that

[Python-ideas] Re: f-string: empty expression should be allowed

2020-10-22 Thread Steven D'Aprano
On Thu, Oct 22, 2020 at 09:09:07AM -0700, Guido van Rossum wrote: > On Thu, Oct 22, 2020 at 3:37 AM Hans Ginzel wrote: > > > Thank you for (ugly) workaorund. > > > > Careful who you're calling ugly. "Who"? Syntax is a person now? For what it's worth, I don't think escaping special symbols is u

[Python-ideas] Dict unpacking assignment

2020-10-22 Thread Steven D'Aprano
I would like to propose dict (or mapping) unpacking assignment. This is inspired in part by the Python-Ideas thread "f-strings as assignment targets", dict unpacking in function calls, and iterable unpacking assignment. Comments welcome. Background -- Iterable unpacking assignment:

[Python-ideas] Re: Call a function at invocation

2020-10-22 Thread 2QdxY4RzWzUUiLuE
On 2020-10-22 at 20:04:14 -0400, Michael Smith wrote: > 1. Being able to call two different functions from the same module. (AND) > 2. Being able to call some functions that exist today without modification > or rearrangement. (AND) > 3. Being able to invoke these things from python without insta

[Python-ideas] Re: Dict unpacking assignment

2020-10-22 Thread Guido van Rossum
Oh, that's quite different than mapping patterns in PEP 634. :-( On Thu, Oct 22, 2020 at 8:28 PM Steven D'Aprano wrote: > I would like to propose dict (or mapping) unpacking assignment. This is > inspired in part by the Python-Ideas thread "f-strings as assignment > targets", dict unpacking in f

[Python-ideas] Re: Bringing the print statement back

2020-10-22 Thread Random832
On Mon, Oct 19, 2020, at 22:41, James T Moon wrote: > tl;dr *boo* *hiss* > > I can only imagine the new Python programmer's look of confusion, > turning to disgust, turning to giving up. Ten years from now, hopefully, Python 2 will be a distant memory, and Python 3.8 will be, at the very least,

[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: Bringing the print statement back

2020-10-22 Thread Henk-Jaap Wagenaar
On Fri, 23 Oct 2020 at 06:35, Random832 wrote: > Does anyone else remember when xkcd first mentioned python? The main > selling point it had for it [and the one that was actually literally true, > vs 'import antigravity' which was a semi-satirical bit about the > batteries-included philosophy] wa

[Python-ideas] Re: f-string: empty expression should be allowed

2020-10-22 Thread Random832
On Thu, Oct 22, 2020, at 21:00, Steven D'Aprano wrote: > "Who"? Syntax is a person now? > > For what it's worth, I don't think escaping special symbols is ugly. > More like homely. It does the job, plainly and simply, but I don't think > it's especially good looking. Every other character stands

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

2020-10-22 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 > te