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 i

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 boolean

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
oes anyone else have examples? -Original Message- From: Python-list On Behalf Of Jonathan Moules Sent: Sunday, July 28, 2019 7:56 AM To: python-list@python.org Subject: Boolean comparison & PEP8 Hi List, Lets say I want to know if the value of `x` is bool(True). My preferred way t

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 si

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 kno

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 >>> No

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 thoug

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 legit

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 comp

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: if

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 greeting

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 solu

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 Engl

Boolean comparison & PEP8

2019-07-28 Thread Jonathan Moules
Hi List, 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 Because this tests both the value and the type. But this appears to be explicitly called out as being "Worse" in PEP8: """ Don't compare boolean values to True or False usin