Re: [Python-ideas] Accepting multiple mappings as positional arguments to create dicts

2018-04-11 Thread Mike Miller
Ok, we can haggle the finer details and I admit once you learn the syntax it isn't substantially harder. Simply, I've found the dict() a bit easier to mentally parse at a glance. Also, to add I've always expected multiple args to work with it, and am always surprised when it doesn't. Would n

Re: [Python-ideas] Proposal: A Reduce-Map Comprehension and a "last" builtin

2018-04-11 Thread Paul Moore
On 11 April 2018 at 04:41, Steven D'Aprano wrote: >> > But in a way that more intuitively expresses the intent of the code, it >> > would be great to have more options on the market. >> >> It's worth adding a reminder here that "having more options on the >> market" is pretty directly in contradic

Re: [Python-ideas] Move optional data out of pyc files

2018-04-11 Thread Petr Viktorin
On 04/11/18 06:21, Chris Angelico wrote: On Wed, Apr 11, 2018 at 1:02 PM, Steven D'Aprano wrote: On Wed, Apr 11, 2018 at 10:08:58AM +1000, Chris Angelico wrote: File system limits aren't usually an issue; as you say, even FAT32 can store a metric ton of files in a single directory. I'm more i

Re: [Python-ideas] Move optional data out of pyc files

2018-04-11 Thread Petr Viktorin
On 04/11/18 08:06, Steven D'Aprano wrote: On Wed, Apr 11, 2018 at 02:21:17PM +1000, Chris Angelico wrote: [...] Yes, it will double the number of files. Actually quadruple it, if the annotations and line numbers are in separate files too. But if most of those extra files never need to be open

Re: [Python-ideas] PEP 572: Assignment Expressions (post #4)

2018-04-11 Thread Paul Moore
On 11 April 2018 at 06:32, Chris Angelico wrote: > When a class scope is involved, a naive transformation into a function would > prevent name lookups (as the function would behave like a method). > > class X: > names = ["Fred", "Barney", "Joe"] > prefix = "> " > prefix

Re: [Python-ideas] PEP 572: Assignment Expressions (post #4)

2018-04-11 Thread Chris Angelico
On Wed, Apr 11, 2018 at 6:55 PM, Paul Moore wrote: > On 11 April 2018 at 06:32, Chris Angelico wrote: >> The name ``prefix`` is thus searched for at global scope, ignoring the class >> name. Under the proposed semantics, this name will be eagerly bound, being >> approximately equivalent to:: >> >

Re: [Python-ideas] PEP 572: Assignment Expressions (post #4)

2018-04-11 Thread Paul Moore
On 11 April 2018 at 10:30, Chris Angelico wrote: > The PEP has kinda pivoted a bit since its inception, so I'm honestly > not sure what "original motivating use case" matters. :D I'm just > lumping all the use-cases together at the same priority now. Fair point, and reading this PEP in isolation

Re: [Python-ideas] PEP 572: Assignment Expressions (post #4)

2018-04-11 Thread Clint Hepner
> On 2018 Apr 11 , at 1:32 a, Chris Angelico wrote: > > Wholesale changes since the previous version. Statement-local name > bindings have been dropped (I'm still keeping the idea in the back of > my head; this PEP wasn't the first time I'd raised the concept), and > we're now focusing primarily

Re: [Python-ideas] PEP 572: Assignment Expressions (post #4)

2018-04-11 Thread Kirill Balunov
Great work Chris! Thank you! I do not know whether this is good or bad, but this PEP considers so many different topics, although closely interrelated with each other. 2018-04-11 8:32 GMT+03:00 Chris Angelico : > > Alterations to comprehensions > - > > The current beh

Re: [Python-ideas] PEP 572: Assignment Expressions (post #4)

2018-04-11 Thread Paul Moore
On 11 April 2018 at 13:23, Clint Hepner wrote: >># Even complex expressions can be built up piece by piece >>y = ((eggs := spam()), (cheese := eggs.method()), cheese[eggs]) > I find the assignments make it difficult to pick out what the final > expression looks like. > The first isn't to

Re: [Python-ideas] PEP 572: Assignment Expressions (post #4)

2018-04-11 Thread Chris Angelico
On Wed, Apr 11, 2018 at 10:23 PM, Clint Hepner wrote: >> On 2018 Apr 11 , at 1:32 a, Chris Angelico wrote: >># Similar to the boolean 'or' but checking for None specifically >>x = "default" if (eggs := spam().ham) is None else eggs > >> >># Even complex expressions can be built up pie

Re: [Python-ideas] PEP 572: Assignment Expressions (post #4)

2018-04-11 Thread Paul Moore
On 11 April 2018 at 14:25, Chris Angelico wrote: > On Wed, Apr 11, 2018 at 10:23 PM, Clint Hepner wrote: >>> Differences from regular assignment statements >>> -- >>> >>> An assignment statement can assign to multiple targets:: >>> >>>x = y = z = 0

Re: [Python-ideas] Move optional data out of pyc files

2018-04-11 Thread Erik Bray
On Tue, Apr 10, 2018 at 9:50 PM, Eric V. Smith wrote: > >>> 3. Annotations. They are used mainly by third party tools that >>> statically analyze sources. They are rarely used at runtime. >> >> Even less used than docstrings probably. > > typing.NamedTuple and dataclasses use annotations at runtim

Re: [Python-ideas] PEP 572: Assignment Expressions (post #4)

2018-04-11 Thread Chris Angelico
On Wed, Apr 11, 2018 at 11:03 PM, Kirill Balunov wrote: > Great work Chris! Thank you! > > I do not know whether this is good or bad, but this PEP considers so many > different topics, although closely interrelated with each other. > > 2018-04-11 8:32 GMT+03:00 Chris Angelico : >> >> >> Alteration

Re: [Python-ideas] PEP 572: Assignment Expressions (post #4)

2018-04-11 Thread Chris Angelico
On Wed, Apr 11, 2018 at 11:37 PM, Paul Moore wrote: > On 11 April 2018 at 14:25, Chris Angelico wrote: >> On Wed, Apr 11, 2018 at 10:23 PM, Clint Hepner >> wrote: Differences from regular assignment statements -- An assignment stat

Re: [Python-ideas] Move optional data out of pyc files

2018-04-11 Thread Chris Angelico
On Wed, Apr 11, 2018 at 4:06 PM, Steven D'Aprano wrote: > On Wed, Apr 11, 2018 at 02:21:17PM +1000, Chris Angelico wrote: > > [...] >> > Yes, it will double the number of files. Actually quadruple it, if the >> > annotations and line numbers are in separate files too. But if most of >> > those ext

Re: [Python-ideas] PEP 572: Assignment Expressions (post #4)

2018-04-11 Thread Paul Moore
On 11 April 2018 at 14:54, Chris Angelico wrote: > Sure, if you're just assigning zero to everything. But you could do > that with a statement. What about this: > > q = { > lambda: x := lambda y: z := a := 0, > } > > Yes, it's an extreme example, but look at all those colons and tell me > if y

Re: [Python-ideas] Add more information in the header of pyc files

2018-04-11 Thread Nick Coghlan
On 11 April 2018 at 02:54, Antoine Pitrou wrote: > On Tue, 10 Apr 2018 19:29:18 +0300 > Serhiy Storchaka > wrote: >> >> A bugfix release can fix bugs in bytecode generation. See for example >> issue27286. [1] The part of issue33041 backported to 3.7 and 3.6 is an >> other example. [2] There wer

Re: [Python-ideas] PEP 572: Assignment Expressions (post #4)

2018-04-11 Thread Chris Angelico
On Thu, Apr 12, 2018 at 12:11 AM, Paul Moore wrote: > On 11 April 2018 at 14:54, Chris Angelico wrote: >> Sure, if you're just assigning zero to everything. But you could do >> that with a statement. What about this: >> >> q = { >> lambda: x := lambda y: z := a := 0, >> } >> >> Yes, it's an e

Re: [Python-ideas] Proposal: A Reduce-Map Comprehension and a "last" builtin

2018-04-11 Thread Peter O'Connor
> > It's worth adding a reminder here that "having more options on the > market" is pretty directly in contradiction to the Zen of Python - > "There should be one-- and preferably only one --obvious way to do > it". I've got to start minding my words more. By "options on the market" I more meant

Re: [Python-ideas] PEP 572: Assignment Expressions (post #4)

2018-04-11 Thread Paul Moore
On 11 April 2018 at 15:28, Chris Angelico wrote: > On Thu, Apr 12, 2018 at 12:11 AM, Paul Moore wrote: >> On 11 April 2018 at 14:54, Chris Angelico wrote: >>> Sure, if you're just assigning zero to everything. But you could do >>> that with a statement. What about this: >>> >>> q = { >>> lam

Re: [Python-ideas] Move optional data out of pyc files

2018-04-11 Thread Nick Coghlan
On 11 April 2018 at 02:14, Serhiy Storchaka wrote: > Currently pyc files contain data that is useful mostly for developing and is > not needed in most normal cases in stable program. There is even an option > that allows to exclude a part of this information from pyc files. It is > expected that t

Re: [Python-ideas] PEP 572: Assignment Expressions (post #4)

2018-04-11 Thread Clint Hepner
> On 2018 Apr 11 , at 9:25 a, Chris Angelico wrote: > > On Wed, Apr 11, 2018 at 10:23 PM, Clint Hepner wrote: >>> On 2018 Apr 11 , at 1:32 a, Chris Angelico wrote: >>> # Similar to the boolean 'or' but checking for None specifically >>> x = "default" if (eggs := spam().ham) is None else eg

Re: [Python-ideas] Proposal: A Reduce-Map Comprehension and a "last" builtin

2018-04-11 Thread Chris Angelico
On Thu, Apr 12, 2018 at 12:37 AM, Peter O'Connor wrote: > Let's look at a task where there is "one obvious way" > > Suppose someone asks: "How can I build a list of squares of the first 100 > odd numbers [1, 9, 25, 49, ] in Python?" The answer is now obvious - > few people would do this: > >

Re: [Python-ideas] Proposal: A Reduce-Map Comprehension and a "last" builtin

2018-04-11 Thread Paul Moore
On 11 April 2018 at 15:37, Peter O'Connor wrote: > If people are happy with these solutions and still see no need for the > initialization syntax, we can stop this, but as I see it there is a "hole" > in the language that needs to be filled. Personally, I'm happy with those solutions and see no

Re: [Python-ideas] PEP 572: Assignment Expressions (post #4)

2018-04-11 Thread Kirill Balunov
2018-04-11 16:50 GMT+03:00 Chris Angelico : > > Can you give an example of how your syntax is superior to the more > general option of simply allowing "as" bindings in any location? > > This is not my syntax :) And not even my idea. I just do not understand, and even a little skeptical about allow

Re: [Python-ideas] PEP 572: Assignment Expressions (post #4)

2018-04-11 Thread Chris Angelico
On Thu, Apr 12, 2018 at 12:46 AM, Clint Hepner wrote: > >> On 2018 Apr 11 , at 9:25 a, Chris Angelico wrote: >> I have no idea what the "in" keyword is doing here, but somehow it >> isn't being used for the meaning it currently has in Python. Does your >> alternative require not one but *two* new

Re: [Python-ideas] PEP 572: Assignment Expressions (post #4)

2018-04-11 Thread Nick Coghlan
On 11 April 2018 at 15:32, Chris Angelico wrote: > Wholesale changes since the previous version. Statement-local name > bindings have been dropped (I'm still keeping the idea in the back of > my head; this PEP wasn't the first time I'd raised the concept), and > we're now focusing primarily on ass

Re: [Python-ideas] PEP 572: Assignment Expressions (post #4)

2018-04-11 Thread Paul Moore
On 11 April 2018 at 16:22, Nick Coghlan wrote: > Similar to my suggestion above, you may also want to consider making > this example a filtered comprehension in order to show the proposal in > its best light: > > results = [(x, y, x/y) for x in input_data if (y := f(x) )] Agreed, this is a *m

Re: [Python-ideas] PEP 572: Statement-Local Name Bindings, take three!

2018-04-11 Thread MRAB
On 2018-04-11 04:15, Mike Miller wrote: If anyone is interested I came across this same subject on a blog post and discussion on HN today: - https://www.hillelwayne.com/post/equals-as-assignment/ It says "BCPL also introduced braces as a means of defining blocks.". That bit is wrong, unless "

Re: [Python-ideas] Move optional data out of pyc files

2018-04-11 Thread Terry Reedy
On 4/11/2018 4:26 AM, Petr Viktorin wrote: Currently in Fedora, we ship *both* optimized and non-optimized pycs to make sure both -O and non--O will work nicely without root privilieges. So splitting the docstrings into a separate file would be, for us, a benefit in terms of file size. Curre

Re: [Python-ideas] PEP 572: Assignment Expressions (post #4)

2018-04-11 Thread Brendan Barnwell
On 2018-04-11 05:23, Clint Hepner wrote: I find the assignments make it difficult to pick out what the final expression looks like. I strongly agree with this, and for me I think this is enough to push me to -1 on the whole proposal. For me the classic example case is still the quadratic f

Re: [Python-ideas] PEP 572: Assignment Expressions (post #4)

2018-04-11 Thread Ethan Furman
On 04/10/2018 10:32 PM, Chris Angelico wrote: Title: Assignment Expressions Thank you, Chris, for doing all this! --- Personally, I'm likely to only use this feature in `if` and `while` statements; if the syntax was easier to read inside longer expressions then I might use this elsewhere --

Re: [Python-ideas] PEP 572: Assignment Expressions (post #4)

2018-04-11 Thread Kirill Balunov
2018-04-11 18:01 GMT+03:00 Kirill Balunov : > > > 2018-04-11 16:50 GMT+03:00 Chris Angelico : > >> >> Can you give an example of how your syntax is superior to the more >> general option of simply allowing "as" bindings in any location? >> >> > This is not my syntax :) And not even my idea. I just

Re: [Python-ideas] PEP 572: Assignment Expressions (post #4)

2018-04-11 Thread David Mertz
How about this, Brendan? _, x1, x2 = (D := b**2 - 4*a*c), (-b + sqrt(D))/2, (-b - sqrt(D))/2 I'm not sure I love this, but I don't hate it. On Wed, Apr 11, 2018, 12:50 PM Brendan Barnwell wrote: > On 2018-04-11 05:23, Clint Hepner wrote: > > I find the assignments make it difficult to pick out

Re: [Python-ideas] PEP 572: Assignment Expressions (post #4)

2018-04-11 Thread Paul Moore
On 11 April 2018 at 19:05, David Mertz wrote: > How about this, Brendan? > > _, x1, x2 = (D := b**2 - 4*a*c), (-b + sqrt(D))/2, (-b - sqrt(D))/2 > > I'm not sure I love this, but I don't hate it. Seriously, how is this in any way better than D = b**2 - 4*a*c x1, x2 = (-b + sqrt(D))/2, (-b - sqrt

Re: [Python-ideas] PEP 572: Assignment Expressions (post #4)

2018-04-11 Thread Brendan Barnwell
On 2018-04-11 11:05, David Mertz wrote: How about this, Brendan? _, x1, x2 = (D := b**2 - 4*a*c), (-b + sqrt(D))/2, (-b - sqrt(D))/2 I'm not sure I love this, but I don't hate it. That's clever, but why bother? I can already do this with existing Python: D = b**2 - 4*a*c x1, x2 = (

Re: [Python-ideas] PEP 572: Assignment Expressions (post #4)

2018-04-11 Thread Chris Angelico
On Thu, Apr 12, 2018 at 1:22 AM, Nick Coghlan wrote: >> # Similar to the boolean 'or' but checking for None specifically >> x = "default" if (eggs := spam().ham) is None else eggs >> >> # Even complex expressions can be built up piece by piece >> y = ((eggs := spam()), (cheese := e

Re: [Python-ideas] PEP 572: Assignment Expressions (post #4)

2018-04-11 Thread George Leslie-Waksman
I really like this proposal in the context of `while` loops but I'm lukewarm in other contexts. I specifically like what this would do for repeated calls. Being able to replace all of these md5 = hashlib.md5() with open(filename, 'rb') as file_reader: for chunk in iter(lambda: file_reader.re

Re: [Python-ideas] PEP 572: Assignment Expressions (post #4)

2018-04-11 Thread Chris Angelico
On Thu, Apr 12, 2018 at 3:49 AM, Brendan Barnwell wrote: > On 2018-04-11 05:23, Clint Hepner wrote: >> >> I find the assignments make it difficult to pick out what the final >> expression looks like. > > > I strongly agree with this, and for me I think this is enough to > push me to -1 on

Re: [Python-ideas] PEP 572: Assignment Expressions (post #4)

2018-04-11 Thread Chris Angelico
On Thu, Apr 12, 2018 at 4:38 AM, Ethan Furman wrote: > On 04/10/2018 10:32 PM, Chris Angelico wrote: > >> Title: Assignment Expressions > > > Thank you, Chris, for doing all this! > > --- > > Personally, I'm likely to only use this feature in `if` and `while` > statements; if the syntax was easier

Re: [Python-ideas] PEP 572: Assignment Expressions (post #4)

2018-04-11 Thread Nathan Schneider
On Wed, Apr 11, 2018 at 1:49 PM, Brendan Barnwell wrote: > On 2018-04-11 05:23, Clint Hepner wrote: > >> I find the assignments make it difficult to pick out what the final >> expression looks like. >> > > I strongly agree with this, and for me I think this is enough to > push me to -1 on

Re: [Python-ideas] PEP 572: Assignment Expressions (post #4)

2018-04-11 Thread Chris Angelico
On Thu, Apr 12, 2018 at 5:24 AM, Kirill Balunov wrote: > I find that I wrote very vague, so I'll try in response to my answer to add > some specifics. In general, I find this idea missed in the language and > thank you for trying to fix this! In my opinion it has only a meaning in > certain constr

Re: [Python-ideas] PEP 572: Assignment Expressions (post #4)

2018-04-11 Thread Ethan Furman
On 04/11/2018 02:55 PM, Chris Angelico wrote: On Thu, Apr 12, 2018 at 4:38 AM, Ethan Furman wrote: Context managers and except blocks don't do the same thing though, so it's a false parallel. They assign things to names using `as`. Close enough. ;) The other two are *dangerous* false pa

Re: [Python-ideas] PEP 572: Assignment Expressions (post #4)

2018-04-11 Thread Chris Angelico
On Thu, Apr 12, 2018 at 9:03 AM, Ethan Furman wrote: > On 04/11/2018 02:55 PM, Chris Angelico wrote: >> >> On Thu, Apr 12, 2018 at 4:38 AM, Ethan Furman wrote: > >> Context managers and except blocks don't do the same thing though, so >> it's a false parallel. > > They assign things to names using

Re: [Python-ideas] PEP 572: Assignment Expressions (post #4)

2018-04-11 Thread Ethan Furman
On 04/11/2018 04:46 PM, Chris Angelico wrote: For myself, I've been back and forth a bit about whether "as" or ":=" is the better option. Both of them have problems. Both of them create edge cases that could cause problems. Since the problems caused by ":=" are well known from other languages (a

Re: [Python-ideas] PEP 572: Assignment Expressions (post #4)

2018-04-11 Thread Chris Angelico
On Thu, Apr 12, 2018 at 10:44 AM, Ethan Furman wrote: > On 04/11/2018 04:46 PM, Chris Angelico wrote: > >> For myself, I've been back and forth a bit about whether "as" or ":=" >> is the better option. Both of them have problems. Both of them create >> edge cases that could cause problems. Since t

Re: [Python-ideas] Move optional data out of pyc files

2018-04-11 Thread Steven D'Aprano
On Thu, Apr 12, 2018 at 12:09:38AM +1000, Chris Angelico wrote: [...] > >> Consider a very common use-case: an OS-provided > >> Python interpreter whose files are all owned by 'root'. Those will be > >> distributed with .pyc files for performance, but you don't want to > >> deprive the users of he

Re: [Python-ideas] Move optional data out of pyc files

2018-04-11 Thread Chris Angelico
On Thu, Apr 12, 2018 at 11:59 AM, Steven D'Aprano wrote: > On Thu, Apr 12, 2018 at 12:09:38AM +1000, Chris Angelico wrote: > > [...] >> >> Consider a very common use-case: an OS-provided >> >> Python interpreter whose files are all owned by 'root'. Those will be >> >> distributed with .pyc files f

[Python-ideas] flatten multi-nested list/set/tuple and certain types.

2018-04-11 Thread delta114514
I thought that itertools.chain.from_iterable isn't useful. cuz this only allow "single-nested iterable -- this will raise error when arg has non-nested element--" like below:: >>> from itertools import chain >>> chain.from_iterable([1]) >>> list(_) Traceback (most recent call last): File "", li

[Python-ideas] Proposal: flatten multi-nested list/tuple/set and other certain class/type.

2018-04-11 Thread delta114514
I thought that itertools.chain.from_iterable isn't useful. cuz this only allow "single-nested iterable -- this will raise error when arg has non-nested element--" like below:: >>> from itertools import chain >>> chain.from_iterable([1]) >>> list(_) Traceback (most recent call last): File "", li

Re: [Python-ideas] PEP 572: Assignment Expressions (post #4)

2018-04-11 Thread Stephen J. Turnbull
Nick Coghlan writes: > > # Similar to the boolean 'or' but checking for None specifically > > x = "default" if (eggs := spam().ham) is None else eggs > > > > # Even complex expressions can be built up piece by piece > > y = ((eggs := spam()), (cheese := eggs.method()), cheese[

Re: [Python-ideas] PEP 572: Assignment Expressions (post #4)

2018-04-11 Thread Michel Desmoulin
Le 11/04/2018 à 23:34, George Leslie-Waksman a écrit : > I really like this proposal in the context of `while` loops but I'm > lukewarm in other contexts. > > I specifically like what this would do for repeated calls. > > ... > > md5 = hashlib.md5() > with open(filename, 'rb') as file_reader:

Re: [Python-ideas] PEP 572: Assignment Expressions (post #4)

2018-04-11 Thread Chris Angelico
On Thu, Apr 12, 2018 at 4:45 PM, Michel Desmoulin wrote: > > > Le 11/04/2018 à 23:34, George Leslie-Waksman a écrit : >> I really like this proposal in the context of `while` loops but I'm >> lukewarm in other contexts. >> >> I specifically like what this would do for repeated calls. >> >> ... >>