[Python-Dev] (name := expression) doesn't fit the narrative of PEP 20 (original) (raw)
Kirill Balunov kirillbalunov at gmail.com
Thu Apr 26 14:24:45 EDT 2018
- Previous message (by thread): [Python-Dev] (name := expression) doesn't fit the narrative of PEP 20
- Next message (by thread): [Python-Dev] (name := expression) doesn't fit the narrative of PEP 20
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
2018-04-26 13:20 GMT+03:00 Steve Holden <steve at holdenweb.com>:
On Thu, Apr 26, 2018 at 8:56 AM, Steven D'Aprano <steve at pearwood.info> wrote:
On Thu, Apr 26, 2018 at 03:31:13AM -0400, Terry Reedy wrote: > On 4/25/2018 8:20 PM, Chris Angelico wrote: > >On Thu, Apr 26, 2018 at 10:11 AM, Yury Selivanov > ><yselivanov.ml at gmail.com> wrote: > >>Just yesterday this snippet was used on python-dev to show how great the > >>new syntax is: > >> > >> myfunc(arg, buffer=(buf := [None]*getsize()), size=len(buf)) > > What strikes me as awful about this example is that len(buf) is > getsize(), so the wrong value is being named and saved. > 'size=len(buf)' is, in a sense, backwards.
Terry is absolutely right, and I'm to blame for that atrocity. Mea culpa. ​Perhaps a better spelling would be myfunc(arg, buffer=[None]*(buflen := getsize()), size=buflen) I know it is non productive and spamy (I promise, this is the last) since
as
syntax is dead. In many cases, there is not much difference in perception between:=
andas
. But in several situations, like this one and as Ethan pointed up-thread - the expression first syntax makes obvious the intent and linearly readable:
my_func(arg, buffer=[None]*get_size() as buf, size=buf)
In any case, it is rather an anti-pattern than a good example to follow.
p.s.: as Victor Stinner wrote on twitter that previously, there was a similar PEP in spirit - "PEP 379 -- Adding an Assignment Expression", which was withdrawn. May be it is worth to make a link to it in the current PEP.
With kind regards, -gdg -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-dev/attachments/20180426/83ebb98a/attachment-0001.html>
- Previous message (by thread): [Python-Dev] (name := expression) doesn't fit the narrative of PEP 20
- Next message (by thread): [Python-Dev] (name := expression) doesn't fit the narrative of PEP 20
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]