Re: [Python-Dev] Assignment expression and coding style: the while True case

2018-07-05 Thread Victor Stinner
Hi, I wrote more pull requests in the meanwhile to see how assignment expressions could be used in the standard library. I combined my 5 PR into a new single PR to see all changes at once: https://github.com/python/cpython/pull/8122/files Again, all these PR must not be merged. I only wrote

Re: [Python-Dev] Assignment expression and coding style: the while True case

2018-07-05 Thread Tim Peters
[Victor Stinner] > FYI I'm trying to use assignment expressions on the stdlib because > *all* examples of the PEP 572 look artificial to me. > All the examples in my Appendix A were derived from real. pre-existing code (although mostly my own). It's turned out that several others with your

Re: [Python-Dev] Assignment expression and coding style: the while True case

2018-07-05 Thread Victor Stinner
2018-07-05 9:10 GMT+02:00 Tim Peters : > I'm all in favor of what Victor is doing: looking at how this stuff will > work in actual code. That's a great antidote to the spread of theoretical > fears. FYI I'm trying to use assignment expressions on the stdlib because *all* examples of the PEP 572

Re: [Python-Dev] Assignment expression and coding style: the while True case

2018-07-05 Thread Ivan Pozdeev via Python-Dev
On 05.07.2018 9:47, Steven D'Aprano wrote: On Thu, Jul 05, 2018 at 12:51:37AM +0200, Victor Stinner wrote: I propose to start the discussion about "coding style" (where are assignment expressions appropriate or not?) with the "while True" case. We don't even have an official implementation

Re: [Python-Dev] Assignment expression and coding style: the while True case

2018-07-05 Thread Antoine Pitrou
On Thu, 5 Jul 2018 13:58:42 +0300 Ivan Pozdeev via Python-Dev wrote: > On 05.07.2018 9:23, Serhiy Storchaka wrote: > > 05.07.18 01:51, Victor Stinner пише: > >> == Pattern 1, straighforward == > >> > >> while True: > >> line = input.readline() > >> if not line: > >> break >

Re: [Python-Dev] Assignment expression and coding style: the while True case

2018-07-05 Thread Ivan Pozdeev via Python-Dev
On 05.07.2018 9:23, Serhiy Storchaka wrote: 05.07.18 01:51, Victor Stinner пише: == Pattern 1, straighforward == while True: line = input.readline() if not line: break ... IMHO here assingment expression is appropriate here. The code remains straighfoward to read.

Re: [Python-Dev] Assignment expression and coding style: the while True case

2018-07-05 Thread Tim Peters
[Victor Stinner] > > > I propose to start the discussion about "coding style" (where are > > assignment expressions appropriate or not?) with the "while True" > > case. > [Steven D'Aprano] > We don't even have an official implementation yet, and you already want > to start prescribing coding

Re: [Python-Dev] Assignment expression and coding style: the while True case

2018-07-05 Thread Steven D'Aprano
On Thu, Jul 05, 2018 at 12:51:37AM +0200, Victor Stinner wrote: > I propose to start the discussion about "coding style" (where are > assignment expressions appropriate or not?) with the "while True" > case. We don't even have an official implementation yet, and you already want to start

Re: [Python-Dev] Assignment expression and coding style: the while True case

2018-07-05 Thread Serhiy Storchaka
05.07.18 03:03, Victor Stinner пише: +labels = [slabel for label + in self._file.readline()[1:].split(b',') + if (slabel := label.strip())] labels = [slabel for label in

Re: [Python-Dev] Assignment expression and coding style: the while True case

2018-07-05 Thread Serhiy Storchaka
05.07.18 01:51, Victor Stinner пише: == Pattern 1, straighforward == while True: line = input.readline() if not line: break ... IMHO here assingment expression is appropriate here. The code remains straighfoward to read. while (line := input.readline()): ... We

Re: [Python-Dev] Assignment expression and coding style: the while True case

2018-07-04 Thread Ivan Pozdeev via Python-Dev
On 05.07.2018 1:51, Victor Stinner wrote: Hi, Let's say that the PEP 572 (assignment expression) is going to be approved. Let's move on and see how it can be used in the Python stdlib. I propose to start the discussion about "coding style" (where are assignment expressions appropriate or not?)

Re: [Python-Dev] Assignment expression and coding style: the while True case

2018-07-04 Thread Rob Cliffe via Python-Dev
On 05/07/2018 00:15, Nathaniel Smith wrote: On Wed, Jul 4, 2018 at 3:51 PM, Victor Stinner wrote: My question is now: for which "while True" patterns are the assignment expression appropriate? There identified different patterns. == Pattern 1, straighforward == while True: line =

Re: [Python-Dev] Assignment expression and coding style: the while True case

2018-07-04 Thread Rob Cliffe via Python-Dev
On 05/07/2018 01:25, Tim Peters wrote: == Pattern 5, two variables == while True:     m = match()     if not m:         break     j = m.end()     if i == j:         break     ... replaced with: while (m := match()) and (j := m.end()) == i: I

Re: [Python-Dev] Assignment expression and coding style: the while True case

2018-07-04 Thread Ivan Pozdeev via Python-Dev
On 05.07.2018 3:36, Chris Angelico wrote: On Thu, Jul 5, 2018 at 10:33 AM, Victor Stinner wrote: 2018-07-05 2:15 GMT+02:00 Chris Angelico : On Thu, Jul 5, 2018 at 10:03 AM, Victor Stinner wrote: On the 3360 for loops of the stdlib (*), I only found 2 loops which would benefit of assignment

Re: [Python-Dev] Assignment expression and coding style: the while True case

2018-07-04 Thread MRAB
On 2018-07-05 01:11, Victor Stinner wrote: The code comes from Lib/_pyio.py. Simplified code: --- nodata_val = b"" ... if n is None or n == -1: ... current_size = 0 while True: chunk = self.raw.read() if chunk in empty_values: nodata_val = chunk

Re: [Python-Dev] Assignment expression and coding style: the while True case

2018-07-04 Thread Chris Angelico
On Thu, Jul 5, 2018 at 10:33 AM, Victor Stinner wrote: > 2018-07-05 2:15 GMT+02:00 Chris Angelico : >> On Thu, Jul 5, 2018 at 10:03 AM, Victor Stinner wrote: >>> On the 3360 for loops of the stdlib (*), I only found 2 loops which >>> would benefit of assignment expressions. >>> >>> It's not easy

Re: [Python-Dev] Assignment expression and coding style: the while True case

2018-07-04 Thread Victor Stinner
2018-07-05 2:15 GMT+02:00 Chris Angelico : > On Thu, Jul 5, 2018 at 10:03 AM, Victor Stinner wrote: >> On the 3360 for loops of the stdlib (*), I only found 2 loops which >> would benefit of assignment expressions. >> >> It's not easy to find loops which: >> - build a list, >> - are simple enough

Re: [Python-Dev] Assignment expression and coding style: the while True case

2018-07-04 Thread Tim Peters
[Victor Stinner]Let's say that the PEP 572 (assignment expression) is going to be > approved. Let's move on and see how it can be used in the Python stdlib. > Ugh - how adult ;-) > I propose to start the discussion about "coding style" (where are > assignment expressions appropriate or not?)

Re: [Python-Dev] Assignment expression and coding style: the while True case

2018-07-04 Thread Chris Angelico
On Thu, Jul 5, 2018 at 10:03 AM, Victor Stinner wrote: > On the 3360 for loops of the stdlib (*), I only found 2 loops which > would benefit of assignment expressions. > > It's not easy to find loops which: > - build a list, > - are simple enough to be expressed as list comprehension, > - use a

Re: [Python-Dev] Assignment expression and coding style: the while True case

2018-07-04 Thread Victor Stinner
The code comes from Lib/_pyio.py. Simplified code: --- nodata_val = b"" ... if n is None or n == -1: ... current_size = 0 while True: chunk = self.raw.read() if chunk in empty_values: nodata_val = chunk break current_size += len(chunk)

Re: [Python-Dev] Assignment expression and coding style: the while True case

2018-07-04 Thread Victor Stinner
On the 3360 for loops of the stdlib (*), I only found 2 loops which would benefit of assignment expressions. It's not easy to find loops which: - build a list, - are simple enough to be expressed as list comprehension, - use a condition (if), - use an expression different than just a variable

Re: [Python-Dev] Assignment expression and coding style: the while True case

2018-07-04 Thread MRAB
On 2018-07-04 23:51, Victor Stinner wrote: [snip] (C) while True: chunk = self.raw.read() if chunk in empty_values: nodata_val = chunk break ... "nodata_val = chunk" cannot be put into the "chunk := self.raw.read()" assignment expression combined with a test.

Re: [Python-Dev] Assignment expression and coding style: the while True case

2018-07-04 Thread Nathaniel Smith
On Wed, Jul 4, 2018 at 3:51 PM, Victor Stinner wrote: > My question is now: for which "while True" patterns are the assignment > expression appropriate? There identified different patterns. > > > == Pattern 1, straighforward == > > while True: > line = input.readline() > if not line: >

[Python-Dev] Assignment expression and coding style: the while True case

2018-07-04 Thread Victor Stinner
Hi, Let's say that the PEP 572 (assignment expression) is going to be approved. Let's move on and see how it can be used in the Python stdlib. I propose to start the discussion about "coding style" (where are assignment expressions appropriate or not?) with the "while True" case. I wrote a WIP