[Python-ideas] Re: Deprecate sum of lists

2021-06-17 Thread Serhiy Storchaka
17.06.21 06:03, David Mertz пише: > I'm sympathetic to raising an exception on `sum(list_of_lists)` similar > to `sum(list_of_strings)`.  But what exactly is the recommended > substitute?  We have this: > > list(chain.from_iterable(list_of_lists)) > > Which is pretty nice, and what I'd probably d

[Python-ideas] Re: Deprecate sum of lists

2021-06-17 Thread Steven D'Aprano
On Wed, Jun 16, 2021 at 04:01:24PM -0700, Christopher Barker wrote: > I’m pretty sure that using sum with strings was a real issue in real code > before it was disallowed. But not with the sum() function, which has prohibited strings from it's introduction in 2.3 :-) https://docs.python.org/rel

[Python-ideas] Re: Deprecate sum of lists

2021-06-17 Thread Steven D'Aprano
On Wed, Jun 16, 2021 at 10:13:40PM -0700, Christopher Barker wrote: > If, as suggested, flattening a list of lists is a common operation, a nice > clean and efficient built in way to do it would be reasonable. Heck, you > could make it a list method :-) People have been talking about a flatten bu

[Python-ideas] Re: Deprecate sum of lists

2021-06-17 Thread Oliver Margetts
Arbitrary and complex nested structures do seem like they would require a complex solution. OTOH `more_itertools.flatten` seems ergonomic - and it is very simple, just a wrapper around `itertools.chain.from_iterable` with a memorable name. If that's the preferred solution, nudging users in the di

[Python-ideas] Re: Introduce constant variables in Python

2021-06-17 Thread Wes Turner
On Mon, May 24, 2021 at 5:43 PM Chris Angelico wrote: > > Requiring that a name not be rebound is well-defined and testable. > Requiring that an object not change is either trivial (in the case of, > say, an integer) or virtually impossible (in the case of most > objects). > What would be the a

[Python-ideas] Re: Introduce constant variables in Python

2021-06-17 Thread Chris Angelico
On Fri, Jun 18, 2021 at 12:43 AM Wes Turner wrote: > > > What would be the advantage of such a declaration? > > Constants don't need to be locked or unlocked; which is advantageous for > parallelism and reasoning about program correctness. > True consts (wherein everything referred to in that obj

[Python-ideas] Re: Introduce constant variables in Python

2021-06-17 Thread Wes Turner
On Thu, Jun 17, 2021 at 10:50 AM Chris Angelico wrote: > On Fri, Jun 18, 2021 at 12:43 AM Wes Turner wrote: > > > > > What would be the advantage of such a declaration? > > > > Constants don't need to be locked or unlocked; which is advantageous for > parallelism and reasoning about program corr

[Python-ideas] Re: Introduce constant variables in Python

2021-06-17 Thread Stephen J. Turnbull
tabeb qena writes: > Great Idea, I have joined the mailing list to write the same idea. > > As I can't find the great difference between Final and Constant, > So, I will use the name Final. > > I suggest one the following syntax: The syntaxes proposed already are fine. The problem is mo

[Python-ideas] Re: Deprecate sum of lists

2021-06-17 Thread Stephen J. Turnbull
Chris Angelico writes: > Insufficiently trolly - lacks walrus operator. :) > > >>> l = [[1,2],[3,4],[5,6],[7,8],[9]] > >>> any(map((x:=[]).extend, l)) or x > [1, 2, 3, 4, 5, 6, 7, 8, 9] > > ChrisA This you? https://mobile.twitter.com/Tr0llyTr0llFace/photo :-)

[Python-ideas] Re: "except;" - semicolon after except, to get rid of indentation when doing error recovery

2021-06-17 Thread Stephen J. Turnbull
Chris Angelico writes: > But logically, there is a significant difference between putting code > inside the except block, and having "except X: pass" and then putting > code after. Code should be written the way it's meant to be, not the > way that happens to work. Technical point: doesn't th

[Python-ideas] Re: "except;" - semicolon after except, to get rid of indentation when doing error recovery

2021-06-17 Thread Chris Angelico
On Fri, Jun 18, 2021 at 3:42 AM Stephen J. Turnbull wrote: > > Chris Angelico writes: > > > But logically, there is a significant difference between putting code > > inside the except block, and having "except X: pass" and then putting > > code after. Code should be written the way it's meant t

[Python-ideas] Re: Deprecate sum of lists

2021-06-17 Thread Chris Angelico
On Fri, Jun 18, 2021 at 3:43 AM Stephen J. Turnbull wrote: > > Chris Angelico writes: > > > Insufficiently trolly - lacks walrus operator. :) > > > > >>> l = [[1,2],[3,4],[5,6],[7,8],[9]] > > >>> any(map((x:=[]).extend, l)) or x > > [1, 2, 3, 4, 5, 6, 7, 8, 9] > > > > ChrisA > > This you? >

[Python-ideas] Re: Deprecate sum of lists

2021-06-17 Thread Christopher Barker
On Wed, Jun 16, 2021 at 10:24 PM David Mertz wrote: > > If you read the BPO the OP linked, that was a suggested patch to optimize >> sum(list_of_lists) -- I'm not sure that's such a bad idea after all. >> > > The proposal was to drop in .__iadd__() for .__add__(), wasn't it? As a > heavy NumPy us

[Python-ideas] Re: Deprecate sum of lists

2021-06-17 Thread Ben Rudiak-Gould
On Thu, Jun 17, 2021 at 12:37 AM Serhiy Storchaka wrote: > And it is equivalent to pure Python code > > [x for chunk in list_of_lists for x in chunk] > Okay, slightly off-topic, but can we *please* allow [*chunk for chunk in list_of_lists] some day. I think it was left out because some

[Python-ideas] Re: Deprecate sum of lists

2021-06-17 Thread David Mertz
On Thu, Jun 17, 2021, 5:24 PM Ben Rudiak-Gould > Okay, slightly off-topic, but can we *please* allow > > [*chunk for chunk in list_of_lists] > It is completely non-obvious to me what that would even MEAN. I cannot derive anything obvious from other uses of *. If I had to guess, I'd think tha

[Python-ideas] Re: Deprecate sum of lists

2021-06-17 Thread Jelle Zijlstra
El jue, 17 jun 2021 a las 14:45, David Mertz () escribió: > On Thu, Jun 17, 2021, 5:24 PM Ben Rudiak-Gould > >> Okay, slightly off-topic, but can we *please* allow >> >> [*chunk for chunk in list_of_lists] >> > > It is completely non-obvious to me what that would even MEAN. I cannot > derive a

[Python-ideas] Re: Deprecate sum of lists

2021-06-17 Thread David Mertz
On Thu, Jun 17, 2021 at 5:52 PM Jelle Zijlstra wrote: > El jue, 17 jun 2021 a las 14:45, David Mertz () escribió: > >> On Thu, Jun 17, 2021, 5:24 PM Ben Rudiak-Gould >> >>> Okay, slightly off-topic, but can we *please* allow >>> >>> [*chunk for chunk in list_of_lists] >>> >> > It is complete

[Python-ideas] Re: Deprecate sum of lists

2021-06-17 Thread Steven D'Aprano
On Thu, Jun 17, 2021 at 02:22:29PM -0700, Ben Rudiak-Gould wrote: > Okay, slightly off-topic, but can we *please* allow > > [*chunk for chunk in list_of_lists] What would that do? The only thing I can guess it would do is the equivalent of: result = [] for chunk in list_of_lists:

[Python-ideas] Re: Deprecate sum of lists

2021-06-17 Thread Steven D'Aprano
On Thu, Jun 17, 2021 at 02:51:44PM -0700, Jelle Zijlstra wrote: > El jue, 17 jun 2021 a las 14:45, David Mertz () escribió: > > > On Thu, Jun 17, 2021, 5:24 PM Ben Rudiak-Gould > > > >> Okay, slightly off-topic, but can we *please* allow > >> > >> [*chunk for chunk in list_of_lists] > My read

[Python-ideas] Re: Deprecate sum of lists

2021-06-17 Thread Jelle Zijlstra
El jue, 17 jun 2021 a las 15:26, Steven D'Aprano () escribió: > On Thu, Jun 17, 2021 at 02:51:44PM -0700, Jelle Zijlstra wrote: > > El jue, 17 jun 2021 a las 14:45, David Mertz () > escribió: > > > > > On Thu, Jun 17, 2021, 5:24 PM Ben Rudiak-Gould > > > > > >> Okay, slightly off-topic, but can we

[Python-ideas] Re: Deprecate sum of lists

2021-06-17 Thread Ben Rudiak-Gould
On Thu, Jun 17, 2021 at 3:09 PM Steven D'Aprano wrote: > On Thu, Jun 17, 2021 at 02:22:29PM -0700, Ben Rudiak-Gould wrote: > > [*chunk for chunk in list_of_lists] > > What would that do? The difference between chunk and *chunk in the expression of a list comprehension would be the same as t

[Python-ideas] Re: Deprecate sum of lists

2021-06-17 Thread Guido van Rossum
Wow, strong language. Not really helping people see it your way. On Thu, Jun 17, 2021 at 14:26 Ben Rudiak-Gould wrote: > On Thu, Jun 17, 2021 at 12:37 AM Serhiy Storchaka > wrote: > >> And it is equivalent to pure Python code >> >> [x for chunk in list_of_lists for x in chunk] >> > > Okay,