Re: [Python-ideas] True and False are singletons

2019-03-19 Thread Cameron Simpson
On 18Mar2019 08:10, Eric Fahlgren wrote: On Mon, Mar 18, 2019 at 7:04 AM Rhodri James wrote: On 18/03/2019 12:19, Richard Damon wrote: > On 3/18/19 7:27 AM, Greg Ewing wrote: >> Juancarlo Añez wrote: >> >>> if settings[MY_KEY] is True: >>> ... >> >> If I saw code like this, it woul

Re: [Python-ideas] True and False are singletons

2019-03-19 Thread Serhiy Storchaka
18.03.19 22:52, Wes Turner пише: >>> True = 1   File "", line 1 SyntaxError: can't assign to keyword The error message will be changed in 3.8. >>> True = 1 File "", line 1 SyntaxError: cannot assign to True ___ Python-ideas mailing list Python-i

Re: [Python-ideas] True and False are singletons

2019-03-19 Thread Serhiy Storchaka
18.03.19 22:58, Greg Ewing пише: Oleg Broytman wrote:    Three-way (tri state) checkbox. You have to distinguish False and None if the possible valuse are None, False and True. In that case the conventional way to write it would be     if settings[MY_KEY] == True:     ... It's not a ma

Re: [Python-ideas] True and False are singletons

2019-03-18 Thread Steven D'Aprano
On Tue, Mar 19, 2019 at 11:32:56AM +1300, Greg Ewing wrote: > Tim Delaney wrote: > >I would argue the opposite - the use of "is" shows a clear knowledge > >that True and False are each a singleton and the author explicitly > >intended to use them that way. > > I don't think you can infer that. I

Re: [Python-ideas] True and False are singletons

2019-03-18 Thread Stephan Hoyer
On Mon, Mar 18, 2019 at 3:42 PM Greg Ewing wrote: > Tim Delaney wrote: > > I would argue the opposite - the use of "is" shows a clear knowledge > > that True and False are each a singleton and the author explicitly > > intended to use them that way. > > I don't think you can infer that. It could

Re: [Python-ideas] True and False are singletons

2019-03-18 Thread Steven D'Aprano
On Mon, Mar 18, 2019 at 10:32:38PM +1100, Chris Angelico wrote: > "Singleton" technically means that there is only one such object. True, but it is common to abuse the term to mean only a fixed, small number of such objects, since "duoton" (for two) and "tripleton" (for three) have never caught

Re: [Python-ideas] True and False are singletons

2019-03-18 Thread Greg Ewing
Tim Delaney wrote: I would argue the opposite - the use of "is" shows a clear knowledge that True and False are each a singleton and the author explicitly intended to use them that way. I don't think you can infer that. It could equally well be someone who's *not* familiar with Python truth ru

Re: [Python-ideas] True and False are singletons

2019-03-18 Thread Steven D'Aprano
On Tue, Mar 19, 2019 at 09:58:55AM +1300, Greg Ewing wrote: > Oleg Broytman wrote: > > Three-way (tri state) checkbox. You have to distinguish False and > >None if the possible valuse are None, False and True. > > In that case the conventional way to write it would be > > if settings[MY_KEY

Re: [Python-ideas] True and False are singletons

2019-03-18 Thread Tim Delaney
On Tue, 19 Mar 2019 at 08:42, Greg Ewing wrote: > Oleg Broytman wrote: > >Three-way (tri state) checkbox. You have to distinguish False and > > None if the possible valuse are None, False and True. > > In that case the conventional way to write it would be > > if settings[MY_KEY] == True

Re: [Python-ideas] True and False are singletons

2019-03-18 Thread David Mertz
There are few cases where I would approve of 'if x is True'. However, the names used in the example suggest it could be one of those rare cases. Settings of True/False/None (i.e. not set) seem like a reasonable pattern. In fact, in code like that, merely "truthy" values are probably a bug that shou

Re: [Python-ideas] True and False are singletons

2019-03-18 Thread David Mertz
It was a VERY long time ago when True and False were not singletons. I don't think we should still try to write code based on rules that stopped applying more than a decade ago. On Mon, Mar 18, 2019, 5:42 PM Greg Ewing wrote: > Oleg Broytman wrote: > >Three-way (tri state) checkbox. You have

Re: [Python-ideas] True and False are singletons

2019-03-18 Thread Greg Ewing
Richard Damon wrote: On 3/18/19 7:27 AM, Greg Ewing wrote: if settings[MY_KEY]: ... > That means something VERY different. Yes, but there needs to be justification for why the difference matters and why this particular way is the best way to deal with it. Whenever you write 'x is

Re: [Python-ideas] True and False are singletons

2019-03-18 Thread Greg Ewing
Oleg Broytman wrote: Three-way (tri state) checkbox. You have to distinguish False and None if the possible valuse are None, False and True. In that case the conventional way to write it would be if settings[MY_KEY] == True: ... It's not a major issue, but I get nervous when I

Re: [Python-ideas] True and False are singletons

2019-03-18 Thread Chris Angelico
On Tue, Mar 19, 2019 at 7:53 AM Wes Turner wrote: > > 'True' is a keyword. (Which is now immutable in Python 3.X?) > > >>> True = 1 > File "", line 1 > SyntaxError: can't assign to keyword In Python 3, the source code token "True" is a keyword literal that always represents the bool value True.

Re: [Python-ideas] True and False are singletons

2019-03-18 Thread Wes Turner
'True' is a keyword. (Which is now immutable in Python 3.X?) >>> True = 1 File "", line 1 SyntaxError: can't assign to keyword https://docs.python.org/3/reference/datamodel.html#the-standard-type-hierarchy https://docs.python.org/3/search.html?q=singleton - "Since None is a singleton, testing

Re: [Python-ideas] True and False are singletons

2019-03-18 Thread Rhodri James
On 18/03/2019 15:10, Eric Fahlgren wrote: On Mon, Mar 18, 2019 at 7:04 AM Rhodri James wrote: On 18/03/2019 12:19, Richard Damon wrote: On 3/18/19 7:27 AM, Greg Ewing wrote: Juancarlo Añez wrote: if settings[MY_KEY] is True: ... If I saw code like this, it would take a real

Re: [Python-ideas] True and False are singletons

2019-03-18 Thread Eric Fahlgren
On Mon, Mar 18, 2019 at 7:04 AM Rhodri James wrote: > On 18/03/2019 12:19, Richard Damon wrote: > > On 3/18/19 7:27 AM, Greg Ewing wrote: > >> Juancarlo Añez wrote: > >> > >>> if settings[MY_KEY] is True: > >>> ... > >> > >> If I saw code like this, it would take a really good argumen

Re: [Python-ideas] True and False are singletons

2019-03-18 Thread Rhodri James
On 18/03/2019 12:19, Richard Damon wrote: On 3/18/19 7:27 AM, Greg Ewing wrote: Juancarlo Añez wrote:    if settings[MY_KEY] is True:    ... If I saw code like this, it would take a really good argument to convince me that it shouldn't be just     if settings[MY_KEY]:     ...

Re: [Python-ideas] True and False are singletons

2019-03-18 Thread Oleg Broytman
On Tue, Mar 19, 2019 at 12:27:04AM +1300, Greg Ewing wrote: > Juancarlo A?ez wrote: > > >if settings[MY_KEY] is True: > >... > > If I saw code like this, it would take a really good argument to > convince me that it shouldn't be just > > if settings[MY_KEY]: > ... T

Re: [Python-ideas] True and False are singletons

2019-03-18 Thread Richard Damon
On 3/18/19 7:27 AM, Greg Ewing wrote: > Juancarlo Añez wrote: > >>    if settings[MY_KEY] is True: >>    ... > > If I saw code like this, it would take a really good argument to > convince me that it shouldn't be just > >     if settings[MY_KEY]: >     ... > That means something VERY differ

Re: [Python-ideas] True and False are singletons

2019-03-18 Thread Richard Damon
On 3/18/19 7:32 AM, Chris Angelico wrote: > On Mon, Mar 18, 2019 at 10:14 PM Juancarlo Añez wrote: >> It came to my attention that: >> >> In the original PEP True and False are said to be singletons >> https://www.python.org/dev/peps/pep-0285/, but it's not in the Data Model >> https://docs.pyth

Re: [Python-ideas] True and False are singletons

2019-03-18 Thread Greg Ewing
Juancarlo Añez wrote: if settings[MY_KEY] is True: ... If I saw code like this, it would take a really good argument to convince me that it shouldn't be just if settings[MY_KEY]: ... -- Greg ___ Python-ideas mailing list Pytho

Re: [Python-ideas] True and False are singletons

2019-03-18 Thread Chris Angelico
On Mon, Mar 18, 2019 at 10:14 PM Juancarlo Añez wrote: > > It came to my attention that: > > In the original PEP True and False are said to be singletons > https://www.python.org/dev/peps/pep-0285/, but it's not in the Data Model > https://docs.python.org/3/reference/datamodel.html > > > This ca

Re: [Python-ideas] True and False are singletons

2019-03-18 Thread Rémi Lapeyre
Le 18 mars 2019 à 12:15:05, Juancarlo Añez (apal...@gmail.com(mailto:apal...@gmail.com)) a écrit: > It came to my attention that: > > > In the original PEP True and False are said to be singletons > > https://www.python.org/dev/peps/pep-0285/, but it's not in the Data Model > > https://docs.pyth

[Python-ideas] True and False are singletons

2019-03-18 Thread Juancarlo Añez
It came to my attention that: In the original PEP True and False are said to be singletons https://www.python.org/dev/peps/pep-0285/, but it's not in the Data Model https://docs.python.org/3/reference/datamodel.html This came to my attention by code wanting to own the valid values in a dict's ke