[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." > >>> f"Sh

[Python-ideas] Re: f-string code formatting

2020-09-17 Thread Ricky Teachey
On Thu, Sep 17, 2020 at 9:32 PM Wes Turner wrote: > There are a number of refactoring tools for Python. > From https://github.com/beat-no/roper#alternatives : > > ... > Another: https://sourcery.ai/ On Thu, Sep 17, 2020 at 8:27 PM Steven D'Aprano wrote: > >> On Thu, Sep 17, 2020 at 11:47:03PM

[Python-ideas] Re: A shortcut to load a JSON file into a dict : json.loadf

2020-09-17 Thread Wes Turner
There's a small amount of overhead to overloading: - 2x conditionals - 1x function call overhead (additional stack frame) Instead of this approach we could either - inline the existing contents of _load by indenting within the conditional - just add the new code at the top of the function - use mu

[Python-ideas] Re: A shortcut to load a JSON file into a dict : json.loadf

2020-09-17 Thread Christopher Barker
On Thu, Sep 17, 2020 at 8:11 PM Chris Angelico wrote: > On Fri, Sep 18, 2020 at 1:05 PM Christopher Barker > wrote: > > I see the issue here, but isn't that inherent in duck typing? It's not > specific to overloading. In fact the current implementation of json.load() > simply calls the .read() i

[Python-ideas] Re: A shortcut to load a JSON file into a dict : json.loadf

2020-09-17 Thread Chris Angelico
On Fri, Sep 18, 2020 at 1:05 PM Christopher Barker wrote: > I see the issue here, but isn't that inherent in duck typing? It's not > specific to overloading. In fact the current implementation of json.load() > simply calls the .read() in the object passed in. If it does not have a read > method

[Python-ideas] Re: A shortcut to load a JSON file into a dict : json.loadf

2020-09-17 Thread Christopher Barker
On Thu, Sep 17, 2020 at 7:07 PM Inada Naoki wrote: > On Fri, Sep 18, 2020 at 12:07 AM Paolo Lammens > wrote: > > Besides, I don't understand what the downside of overloading is, apart > from purism (?). > I am one of who are conservative about overloading. I agree this is > purism, but I want to

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

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

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

[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? Terri

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

[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: A shortcut to load a JSON file into a dict : json.loadf

2020-09-17 Thread Inada Naoki
On Fri, Sep 18, 2020 at 12:07 AM Paolo Lammens wrote: > > Besides, I don't understand what the downside of overloading is, apart from > purism (?). I am one of who are conservative about overloading. I agree this is purism, but I want to explain behind of this purism. In statically, and nominal

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

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

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

[Python-ideas] Re: f-string code formatting

2020-09-17 Thread Wes Turner
There are a number of refactoring tools for Python. >From https://github.com/beat-no/roper#alternatives : ```rst Alternatives IDEs * PyCharm - https://www.jetbrains.com/help/pycharm/refactoring-source-code.html Editor plugins -- * vim - https://github.com/python-rop

[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__` protocol.

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

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

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

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

[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 f-string

[Python-ideas] Re: Magic attribute for attribute names retrieving

2020-09-17 Thread Steven D'Aprano
On Fri, Sep 18, 2020 at 10:05:07AM +1000, Steven D'Aprano wrote: > Your proposal is to have a magic dunder, spelled '__attrs__` (note the > two additional dots) which converts a attribute access into a string: Oops, the comment about the dots was from an earlier thought which I deleted. Sorry.

[Python-ideas] Re: f-string code formatting

2020-09-17 Thread Steven D'Aprano
On Thu, Sep 17, 2020 at 11:47:03PM -, Joseph Perez wrote: > Thus `f"{:a + b}" == "a + b"`. That can already be done by just *not* using a f-string. This looks like a case of "when the only tool you have is a hammer, everything looks like a nail". If you don't want a string literal to be ev

[Python-ideas] Re: Magic attribute for attribute names retrieving

2020-09-17 Thread Steven D'Aprano
On Thu, Sep 17, 2020 at 08:34:26PM -, Joseph Perez wrote: > A lot of libraries use string for attribute names to do some "dynamic" > things. A typical example are SQLAlchemy > [validators](https://docs.sqlalchemy.org/en/13/orm/mapped_attributes.html#simple-validators): > ```python > from sql

[Python-ideas] f-string code formatting

2020-09-17 Thread Joseph Perez
Note: this suggestion should echo https://mail.python.org/archives/list/python-ideas@python.org/thread/UUFFAI3FZMQRVPDCUPZEOAZCRNXKWFDE/ but has a bigger scope and completely differs in the way to proceed. Currently, Python lacks a way to integrate code parts into string; when I say code, I don

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

[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`_ i

[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, and

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

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

2020-09-17 Thread David Mertz
On Thu, Sep 17, 2020, 2:36 AM Dennis Sweeney wrote: > >>> f"It is {hh}:{mm} {am_or_pm}" = "It is 11:45 PM" > >>> f"It is {hh}:{mm} {am_or_pm}" == "It is 11:45 PM" I cringe at every part of this proposal. But this is especially perplexing. How can it POSSIBLY work, unless we have "spooky

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

2020-09-17 Thread Edwin Zimmerman
On 9/17/2020 6:56 PM, Chris Angelico wrote: > On Fri, Sep 18, 2020 at 8:54 AM Ben Rudiak-Gould wrote: >> This is a terrible idea. >> >> No one should ever be trying to extract data from strings that are obviously >> meant for human consumption, like "It is 11:45 PM". >> >> I'll grant you that it'

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

2020-09-17 Thread Chris Angelico
On Fri, Sep 18, 2020 at 9:00 AM Steven D'Aprano wrote: > > On Thu, Sep 17, 2020 at 06:06:39PM +0200, Alexis Masson wrote: > > > I do really like the idea, but assigning to a literal really makes it > > feel wrong... > > f-strings are not literals. They are a form of eval(). > Oh, that makes 'em s

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

2020-09-17 Thread Steven D'Aprano
On Thu, Sep 17, 2020 at 06:06:39PM +0200, Alexis Masson wrote: > I do really like the idea, but assigning to a literal really makes it > feel wrong... f-strings are not literals. They are a form of eval(). -- Steve ___ Python-ideas mailing list -- p

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

2020-09-17 Thread Chris Angelico
On Fri, Sep 18, 2020 at 8:54 AM Ben Rudiak-Gould wrote: > > This is a terrible idea. > > No one should ever be trying to extract data from strings that are obviously > meant for human consumption, like "It is 11:45 PM". > > I'll grant you that it's sometimes necessary. But it needs to be approach

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

2020-09-17 Thread Ben Rudiak-Gould
This is a terrible idea. No one should ever be trying to extract data from strings that are obviously meant for human consumption, like "It is 11:45 PM". I'll grant you that it's sometimes necessary. But it needs to be approached very carefully. You need to use a --porcelain flag if available, yo

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

2020-09-17 Thread Wes Turner
Maybe it would be best to talk about actual code? What exceptions will be raised? Is there a mismatch between the string format specification and regex? Why would it be suboptimal to specify types for regex match groups within regex strings? Is it any better to specify regexes with f-strings? lo

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

2020-09-17 Thread Christopher Barker
On Thu, Sep 17, 2020 at 1:23 PM Chris Angelico wrote: > > And that's why the directives are NOT just a pure mirroring of format > string directives. Look at C's scanf and printf functions - they > correspond in many ways, but they differ in order to be useful. Exactly -- but the C ones are a lo

[Python-ideas] Re: Magic attribute for attribute names retrieving

2020-09-17 Thread Joseph Perez
Alex Hall wrote: > This sounds a lot like this suggestion to add a nameof function/operator: > https://mail.python.org/archives/list/python-ideas@python.org/thread/UUFFAI3... Indeed, it sounds like the `nameof` operator; I had not heard of this suggestion before your message. However, there is at

[Python-ideas] Re: Magic attribute for attribute names retrieving

2020-09-17 Thread Alex Hall
This sounds a lot like this suggestion to add a nameof function/operator: https://mail.python.org/archives/list/python-ideas@python.org/thread/UUFFAI3FZMQRVPDCUPZEOAZCRNXKWFDE/#IHXME3F5XEQZAN6JSK2PMC4UOWV7AVSF On Thu, Sep 17, 2020 at 10:37 PM Joseph Perez wrote: > A lot of libraries use string f

[Python-ideas] Magic attribute for attribute names retrieving

2020-09-17 Thread Joseph Perez
A lot of libraries use string for attribute names to do some "dynamic" things. A typical example are SQLAlchemy [validators](https://docs.sqlalchemy.org/en/13/orm/mapped_attributes.html#simple-validators): ```python from sqlalchemy.orm import validates class EmailAddress(Base): __tablename__

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

2020-09-17 Thread Chris Angelico
On Fri, Sep 18, 2020 at 6:19 AM Christopher Barker wrote: > > I like the idea of an scans like ability, but I"m afraid the existing format > language is poorly suited to that. > > It's simply no designed to be a two-way street: > > * ANYTHING can be stringified in Python -- so there is no defined

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

2020-09-17 Thread Christopher Barker
I like the idea of an scans like ability, but I"m afraid the existing format language is poorly suited to that. It's simply no designed to be a two-way street: * ANYTHING can be stringified in Python -- so there is no defined way to turn a string back into a particular type. OK, so we restrict o

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

2020-09-17 Thread Alex Hall
On Thu, Sep 17, 2020 at 9:50 PM Ricky Teachey wrote: > On Thu, Sep 17, 2020 at 3:44 PM Alex Hall wrote: > >> >> On Thu, Sep 17, 2020 at 9:27 PM Ricky Teachey wrote: >> >>> A difficulty I have with the idea as presented is this. >>> >>> If I can say this: >>> >>> "{x:d} {y:d} {z:d}" = "1 2 3" >>

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

2020-09-17 Thread Ricky Teachey
On Thu, Sep 17, 2020 at 3:44 PM Alex Hall wrote: > > On Thu, Sep 17, 2020 at 9:27 PM Ricky Teachey wrote: > >> >> On Thu, Sep 17, 2020 at 2:57 PM Brendan Barnwell >> wrote: >> >>> On 2020-09-16 21:52, Dennis Sweeney wrote: >>> > TL;DR: I propose the following behavior: >>> > >>> > >>> s =

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

2020-09-17 Thread Alex Hall
On Thu, Sep 17, 2020 at 9:27 PM Ricky Teachey wrote: > > On Thu, Sep 17, 2020 at 2:57 PM Brendan Barnwell > wrote: > >> On 2020-09-16 21:52, Dennis Sweeney wrote: >> > TL;DR: I propose the following behavior: >> > >> > >>> s = "She turned me into a newt." >> > >>> f"She turned me into

[Python-ideas] Re: locals and exec // f-strings as assignment targets

2020-09-17 Thread Alexis Masson
OK, I admit defeat, you're indeed right. I thought it worked, but it doesn't; well, I've learned something today, thank you for that ! However, I stand firm on my original idea (just the same as what Brendan Barnwell wrote earlier)  : I still think returning a dict is the best way to implem

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

2020-09-17 Thread Ricky Teachey
On Thu, Sep 17, 2020 at 2:57 PM Brendan Barnwell wrote: > On 2020-09-16 21:52, Dennis Sweeney wrote: > > TL;DR: I propose the following behavior: > > > > >>> s = "She turned me into a newt." > > >>> f"She turned me into a {animal}." = s > > >>> animal > > 'newt' > > > > >

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

2020-09-17 Thread Alex Hall
On Thu, Sep 17, 2020 at 8:57 PM Brendan Barnwell wrote: > On 2020-09-16 21:52, Dennis Sweeney wrote: > > TL;DR: I propose the following behavior: > > > > >>> s = "She turned me into a newt." > > >>> f"She turned me into a {animal}." = s > > >>> animal > > 'newt' > > > > >

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

2020-09-17 Thread Eric V. Smith
On 9/17/2020 11:38 AM, Eric V. Smith wrote: In general, there's no way to start with a format specifier string and from it get the type of the object that it should be applied to. For example, any string without %'s is a valid datetime format specifier (of dubious value, but such is life). Perh

[Python-ideas] Re: Python-ideas Digest, Vol 166, Issue 76

2020-09-17 Thread Paul Moore
On Thu, 17 Sep 2020 at 20:07, Chris Angelico wrote: > > On Fri, Sep 18, 2020 at 4:55 AM Alex Hall wrote: > > > > On Thu, Sep 17, 2020 at 8:49 PM Chris Angelico wrote: > >> > >> The only time you can safely mutate locals() is when you're at top > >> level and it's the same as globals(). > > > > >

[Python-ideas] Re: Python-ideas Digest, Vol 166, Issue 76

2020-09-17 Thread Chris Angelico
On Fri, Sep 18, 2020 at 4:55 AM Alex Hall wrote: > > On Thu, Sep 17, 2020 at 8:49 PM Chris Angelico wrote: >> >> The only time you can safely mutate locals() is when you're at top >> level and it's the same as globals(). > > > It's safe in class definitions, right? At least in CPython it seems to

[Python-ideas] Re: Python-ideas Digest, Vol 166, Issue 76

2020-09-17 Thread Alex Hall
On Thu, Sep 17, 2020 at 8:49 PM Chris Angelico wrote: > The only time you can safely mutate locals() is when you're at top > level and it's the same as globals(). > It's safe in class definitions, right? At least in CPython it seems to work. I've done that a few times, most recently to dynamical

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

2020-09-17 Thread Brendan Barnwell
On 2020-09-16 21:52, Dennis Sweeney wrote: TL;DR: I propose the following behavior: >>> s = "She turned me into a newt." >>> f"She turned me into a {animal}." = s >>> animal 'newt' >>> f"A {animal}?" = s Traceback (most recent call last): File "", line 1, in

[Python-ideas] Re: Python-ideas Digest, Vol 166, Issue 76

2020-09-17 Thread Chris Angelico
On Fri, Sep 18, 2020 at 4:32 AM Alexis Masson wrote: > > On Fri, Sep 18, 2020 at 2:13 AM Alexis Masson wrote: > > This, in addition with locals().update(_), feels much better to me. > Furthermore, it would allow other string-like classes, such as bytes or > bytearray, to use that feature. > > B

[Python-ideas] Re: locals and exec

2020-09-17 Thread Alex Hall
On Thu, Sep 17, 2020 at 8:33 PM Alexis Masson wrote: > On Fri, Sep 18, 2020 at 2:13 AM Alexis Masson > wrote: > > This, in addition with locals().update(_), feels much better to me. > Furthermore, it would allow other string-like classes, such as bytes or > bytearray, to use that feature. >

[Python-ideas] Re: Python-ideas Digest, Vol 166, Issue 76

2020-09-17 Thread Alexis Masson
On Fri, Sep 18, 2020 at 2:13 AM Alexis Masson wrote: This, in addition with locals().update(_), feels much better to me. Furthermore, it would allow other string-like classes, such as bytes or bytearray, to use that feature. But locals().update() isn't a supported operation, except in the si

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

2020-09-17 Thread Wes Turner
So this would be a way to (1) rewrite f-strings as regexes; (2) with named capture groups assigned to locals() instead of re.Match.groupdict()? Would it default to `r'(.*?)'` ? https://docs.python.org/3/library/re.html#re.Match.groupdict https://pypi.org/project/regex/ On Thu, Sep 17, 2020, 12:

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

2020-09-17 Thread Ricky Teachey
On Thu, Sep 17, 2020 at 1:39 PM Eric V. Smith wrote: > On 9/17/2020 1:28 PM, Ricky Teachey wrote: > > > > On Thu, Sep 17, 2020 at 1:13 PM Eric V. Smith wrote: > >> >> >> If someone wanted to play with this in pure Python, string.Formatter's >> parse() method would do all of the parsing for you.

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

2020-09-17 Thread Eric V. Smith
On 9/17/2020 1:28 PM, Ricky Teachey wrote: On Thu, Sep 17, 2020 at 1:13 PM Eric V. Smith > wrote: If someone wanted to play with this in pure Python, string.Formatter's parse() method would do all of the parsing for you. Surprisingly it is not *quite

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

2020-09-17 Thread Ricky Teachey
On Thu, Sep 17, 2020 at 1:13 PM Eric V. Smith wrote: > On 9/17/2020 12:24 PM, Chris Angelico wrote: > > On Fri, Sep 18, 2020 at 1:38 AM Eric V. Smith > wrote: > >> In general, there's no way to start with a format specifier string and > >> from it get the type of the object that it should be app

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

2020-09-17 Thread Eric V. Smith
On 9/17/2020 12:24 PM, Chris Angelico wrote: On Fri, Sep 18, 2020 at 1:38 AM Eric V. Smith wrote: In general, there's no way to start with a format specifier string and from it get the type of the object that it should be applied to. For example, any string without %'s is a valid datetime forma

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

2020-09-17 Thread Chris Angelico
On Fri, Sep 18, 2020 at 2:13 AM Alexis Masson wrote: > This, in addition with locals().update(_), feels much better to me. > Furthermore, it would allow other string-like classes, such as bytes or > bytearray, to use that feature. > But locals().update() isn't a supported operation, except in t

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

2020-09-17 Thread Chris Angelico
On Fri, Sep 18, 2020 at 1:38 AM Eric V. Smith wrote: > > In general, there's no way to start with a format specifier string and > from it get the type of the object that it should be applied to. For > example, any string without %'s is a valid datetime format specifier (of > dubious value, but suc

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

2020-09-17 Thread Alexis Masson
TL;DR: I propose the following behavior: >>> s = "She turned me into a newt." >>> f"She turned me into a {animal}." = s >>> animal 'newt' >>> f"A {animal}?" = s Traceback (most recent call last): File "", line 1, in f"A {animal}?" = s ValueEr

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

2020-09-17 Thread Eric V. Smith
In general, there's no way to start with a format specifier string and from it get the type of the object that it should be applied to. For example, any string without %'s is a valid datetime format specifier (of dubious value, but such is life). Perhaps a better example is decimal vs. float. W

[Python-ideas] Re: A shortcut to load a JSON file into a dict : json.loadf

2020-09-17 Thread Paolo Lammens
> On the other hand, the fact that we might be adding two new functions to > four different modules is, in my mind, and argument for overloading the > existing dump() / load() instead. a lot less API churn. I also believe that overloading is the better option here. The whole point of this change

[Python-ideas] Re: Fwd: Re: Experimenting with dict performance, and an immutable dict

2020-09-17 Thread Marco Sulla
On Thu, 17 Sep 2020 at 05:31, Inada Naoki wrote: > > On Thu, Sep 17, 2020 at 8:03 AM Marco Sulla > wrote: > > > > python -m timeit -n 2000 --setup "from uuid import uuid4 ; o = > > {str(uuid4()).replace('-', '') : str(uuid4()).replace('-', '') for i > > in range(1)}" "dict(**o)" > > > > I do

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

2020-09-17 Thread Ricky Teachey
On Thu, Sep 17, 2020 at 9:01 AM Paul Moore wrote: > On Thu, 17 Sep 2020 at 13:38, Dennis Sweeney > wrote: > > > > TL;DR: I propose the following behavior: > > > > >>> s = "She turned me into a newt." > > >>> f"She turned me into a {animal}." = s > > >>> animal > > 'newt' > > Some

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

2020-09-17 Thread Marco Sulla
It seems that the variables come out magically. What about something like: a, b = "hello world".extract("{} {}") PS: I do not like extract, it's the first name that comes in my mind ___ Python-ideas mailing list -- python-ideas@python.org To unsubscrib

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

2020-09-17 Thread Paul Moore
On Thu, 17 Sep 2020 at 14:12, Chris Angelico wrote: > Assigning to an f-string is VERY tempting. It doesn't quite sit right > with me (f-strings feel like literals, even though they aren't, and it > doesn't make sense to assign to a string literal) - but I do like the > concept. If it existed in

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

2020-09-17 Thread Calvin Spealman
I really like the symmetry of this approach. On Thu, Sep 17, 2020 at 8:37 AM Dennis Sweeney wrote: > TL;DR: I propose the following behavior: > > >>> s = "She turned me into a newt." > >>> f"She turned me into a {animal}." = s > >>> animal > 'newt' > > >>> f"A {animal}?" = s

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

2020-09-17 Thread Alex Hall
On Thu, Sep 17, 2020 at 2:38 PM Dennis Sweeney wrote: > === Existing way of achieving this === > > As of now, you could achieve the behavior with regular expressions: > > >>> import re > >>> pattern = re.compile(r'It is (.+):(.+) (.+)') > >>> match = pattern.fullmatch("It is 11:45 PM"

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

2020-09-17 Thread Chris Angelico
On Thu, Sep 17, 2020 at 11:02 PM Paul Moore wrote: > > On Thu, 17 Sep 2020 at 13:38, Dennis Sweeney > wrote: > > > > TL;DR: I propose the following behavior: > > > > >>> s = "She turned me into a newt." > > >>> f"She turned me into a {animal}." = s > > >>> animal > > 'newt' > > So

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

2020-09-17 Thread Paul Moore
On Thu, 17 Sep 2020 at 13:38, Dennis Sweeney wrote: > > TL;DR: I propose the following behavior: > > >>> s = "She turned me into a newt." > >>> f"She turned me into a {animal}." = s > >>> animal > 'newt' Something very similar to this already exists on PyPI: https://pypi.org/proje

[Python-ideas] f-strings as assignment targets

2020-09-17 Thread Dennis Sweeney
TL;DR: I propose the following behavior: >>> s = "She turned me into a newt." >>> f"She turned me into a {animal}." = s >>> animal 'newt' >>> f"A {animal}?" = s Traceback (most recent call last): File "", line 1, in f"A {animal}?" = s ValueError: f-str

[Python-ideas] Re: 'Infinity' constant in Python

2020-09-17 Thread Stephen J. Turnbull
Christopher Barker writes: > Could you all please start another thread if you want to discuss possible > changes to Error handling for floats. Or anything that isn't strictly > adding some names to builtins. This is *all* about adding names to builtins. *Nobody* is seriously proposing changes