Re: Boolean comparison & PEP8

2019-07-29 Thread Michael F. Stemper
On 29/07/2019 12.56, Rob Gaddi wrote: > On 7/29/19 10:44 AM, Michael F. Stemper wrote: >> On 28/07/2019 19.04, Chris Angelico wrote: >>> On Mon, Jul 29, 2019 at 9:48 AM Michael Torrie >>> wrote: Yet the recommended solution to the problem of wanting a default argument of an empty list

Re: Boolean comparison & PEP8

2019-07-29 Thread Rob Gaddi
On 7/29/19 10:44 AM, Michael F. Stemper wrote: On 28/07/2019 19.04, Chris Angelico wrote: On Mon, Jul 29, 2019 at 9:48 AM Michael Torrie wrote: On 7/28/19 5:55 AM, Jonathan Moules wrote: But this appears to be explicitly called out as being "Worse" in PEP8: """ Don't compare boolean values

Re: Boolean comparison & PEP8

2019-07-29 Thread Chris Angelico
On Tue, Jul 30, 2019 at 3:46 AM Michael F. Stemper wrote: > > On 28/07/2019 19.04, Chris Angelico wrote: > > On Mon, Jul 29, 2019 at 9:48 AM Michael Torrie wrote: > >> > >> On 7/28/19 5:55 AM, Jonathan Moules wrote: > >>> But this appears to be explicitly called out as being "Worse" in PEP8: >

Re: Boolean comparison & PEP8

2019-07-29 Thread Michael F. Stemper
On 28/07/2019 19.04, Chris Angelico wrote: > On Mon, Jul 29, 2019 at 9:48 AM Michael Torrie wrote: >> >> On 7/28/19 5:55 AM, Jonathan Moules wrote: >>> But this appears to be explicitly called out as being "Worse" in PEP8: >>> >>> """ >>> Don't compare boolean values to True or False using ==.

Re: Boolean comparison & PEP8

2019-07-29 Thread Chris Angelico
On Tue, Jul 30, 2019 at 12:04 AM David Raymond wrote: > if shell: > #wait, "shell" is not really a statement or an instruction. "If shell"... > what? "I need to shell"? Is this whether we want to use a shell, or if we > discovered that we're already in one? Or is "shell" not really a

Re: Boolean comparison & PEP8

2019-07-29 Thread Dan Sommers
On 7/29/19 10:02 AM, David Raymond wrote: > I think the other part of the discussion to be had here is: how do you > name your booleans? Yep. > ... To me the name of a boolean variable should be obvious that it's a > boolean ... Well, yeah, maybe. If it's really only a boolean, and its value

Re: Boolean comparison & PEP8

2019-07-29 Thread Grant Edwards
On 2019-07-29, Michael Torrie wrote: > On 7/28/19 6:04 PM, Chris Angelico wrote: >> This is a fairly unusual case, though. More commonly, the default >> would be None, not False, and "if bar is None:" is extremely well >> known and idiomatic. > > Ahh yes, true. No... None. ;) -- Grant Edwards

RE: Boolean comparison & PEP8

2019-07-29 Thread David Raymond
I think the other part of the discussion to be had here is: how do you name your booleans? As with other things, "x", and "greeting" aren't really the best names. "greeting" sounds like it should hold what the greeting _is_, not whether or not there _should be_ a greeting. If it were something

Re: Boolean comparison & PEP8

2019-07-28 Thread Terry Reedy
On 7/28/2019 7:55 AM, Jonathan Moules wrote: Lets say I want to know if the value of `x` is bool(True). My preferred way to do it is: if x is True:     pass If you know that expression x is boolean, and one usually knows or should know whether is it or is not, '= True' and 'is True' and

Re: Boolean comparison & PEP8

2019-07-28 Thread Michael Torrie
On 7/28/19 6:04 PM, Chris Angelico wrote: > This is a fairly unusual case, though. More commonly, the default > would be None, not False, and "if bar is None:" is extremely well > known and idiomatic. Ahh yes, true. > This analysis is correct, but the situations where you *actually* want > to

Re: Boolean comparison & PEP8

2019-07-28 Thread Richard Damon
On 7/28/19 8:46 PM, Chris Angelico wrote: > On Mon, Jul 29, 2019 at 10:43 AM Richard Damon > wrote: >> On 7/28/19 8:25 PM, Chris Angelico wrote: >>> Of course, if the third value can be simplified away (eg None means >>> "use the global default"), then you can still just use "if verbose is >>>

Re: Boolean comparison & PEP8

2019-07-28 Thread Grant Edwards
On 2019-07-29, Richard Damon wrote: > On 7/28/19 7:46 PM, Michael Torrie wrote: >> Yet the recommended solution to the problem of wanting a default >> argument of an empty list is something like this: >> >> def foo(bar=False); >> if bar is False: >> bar = [] >> >> > > I

Re: Boolean comparison & PEP8

2019-07-28 Thread Chris Angelico
On Mon, Jul 29, 2019 at 10:43 AM Richard Damon wrote: > > On 7/28/19 8:25 PM, Chris Angelico wrote: > > Of course, if the third value can be simplified away (eg None means > > "use the global default"), then you can still just use "if verbose is > > None:" and then reassign it. But this is a

Re: Boolean comparison & PEP8

2019-07-28 Thread Richard Damon
On 7/28/19 8:25 PM, Chris Angelico wrote: > On Mon, Jul 29, 2019 at 10:15 AM Richard Damon > wrote: >> On 7/28/19 7:46 PM, Michael Torrie wrote: >>> On 7/28/19 5:55 AM, Jonathan Moules wrote: But this appears to be explicitly called out as being "Worse" in PEP8: """ Don't

Re: Boolean comparison & PEP8

2019-07-28 Thread Chris Angelico
On Mon, Jul 29, 2019 at 10:15 AM Richard Damon wrote: > > On 7/28/19 7:46 PM, Michael Torrie wrote: > > On 7/28/19 5:55 AM, Jonathan Moules wrote: > >> But this appears to be explicitly called out as being "Worse" in PEP8: > >> > >> """ > >> Don't compare boolean values to True or False using ==.

Re: Boolean comparison & PEP8

2019-07-28 Thread Richard Damon
On 7/28/19 7:46 PM, Michael Torrie wrote: > On 7/28/19 5:55 AM, Jonathan Moules wrote: >> But this appears to be explicitly called out as being "Worse" in PEP8: >> >> """ >> Don't compare boolean values to True or False using ==. >> >> Yes:   if greeting: >> No:    if greeting == True: >> Worse:

Re: Boolean comparison & PEP8

2019-07-28 Thread Chris Angelico
On Mon, Jul 29, 2019 at 9:48 AM Michael Torrie wrote: > > On 7/28/19 5:55 AM, Jonathan Moules wrote: > > But this appears to be explicitly called out as being "Worse" in PEP8: > > > > """ > > Don't compare boolean values to True or False using ==. > > > > Yes: if greeting: > > No:if

Re: Boolean comparison & PEP8

2019-07-28 Thread Michael Torrie
On 7/28/19 5:55 AM, Jonathan Moules wrote: > But this appears to be explicitly called out as being "Worse" in PEP8: > > """ > Don't compare boolean values to True or False using ==. > > Yes:   if greeting: > No:    if greeting == True: > Worse: if greeting is True: > """ Yet the recommended

Re: Boolean comparison & PEP8

2019-07-28 Thread Marko Rauhamaa
Jonathan Moules : > Lets say I want to know if the value of `x` is bool(True). > My preferred way to do it is: > > if x is True: > [...] > > But this appears to be explicitly called out as being "Worse" in PEP8: > > [...] > > Why? It has primarily to do with the naturalness of expression. In