Re: [Python-ideas] Why operators are useful

2019-03-18 Thread Dan Sommers
On 3/18/19 7:12 PM, Steven D'Aprano wrote: > On Mon, Mar 18, 2019 at 06:34:48PM -0500, Dan Sommers wrote: > >> So how many of you got tired of those three statements and >> added something like the following function to your private >> collection of useful functions: >> >> def

Re: [Python-ideas] Why operators are useful

2019-03-18 Thread Steven D'Aprano
On Mon, Mar 18, 2019 at 06:34:48PM -0500, Dan Sommers wrote: > So how many of you got tired of those three statements and > added something like the following function to your private > collection of useful functions: > > def merged_mappings(mapping, other): > temp = mapping.copy() >

Re: [Python-ideas] Why operators are useful

2019-03-18 Thread Steven D'Aprano
On Mon, Mar 18, 2019 at 05:51:08AM -0700, Rémi Lapeyre wrote: > Maths’ typing is explicit so you don’t need to spend brain cycles to > determine them. Surely that depends on how formal you are being? Maths can vary hugely in formality, even at a professional level. It is a terrible

Re: [Python-ideas] Why operators are useful

2019-03-18 Thread Dan Sommers
On 3/18/19 6:08 PM, Steven D'Aprano wrote: On Mon, Mar 18, 2019 at 03:12:52PM +0100, Antoine Pitrou wrote: (also, don't forget you can still use the copy() + update() method) If we had fluent method calls, we could write: process(mapping.copy().update(other)) but we don't, so we use a

Re: [Python-ideas] Why operators are useful

2019-03-18 Thread Steven D'Aprano
On Sat, Mar 16, 2019 at 07:13:04PM -0400, Terry Reedy wrote: > >     new = a.copy() > >     new.update(b) > >     # do something with new > > In my census of the stdlib, already posted and noted as subject to > error, this was twice as common as all other non-update-in-place >

Re: [Python-ideas] Why operators are useful

2019-03-18 Thread Steven D'Aprano
On Mon, Mar 18, 2019 at 04:07:11PM +0100, Jimmy Girardet wrote: > The syntax {**b,**c} wasn't hard to remember. [...] > And easy because at the end it's idiomatic. It is only idiomatic if moderately experienced Python programmers can automatically read it and write it without thinking about

Re: [Python-ideas] Why operators are useful

2019-03-18 Thread Steven D'Aprano
On Mon, Mar 18, 2019 at 03:12:52PM +0100, Antoine Pitrou wrote: > (also, don't forget you can still use the copy() + update() method) If we had fluent method calls, we could write: process(mapping.copy().update(other)) but we don't, so we use a pointless temporary variable: temp =

Re: [Python-ideas] Why operators are useful

2019-03-18 Thread Elazar
בתאריך יום ג׳, 19 במרץ 2019, 0:41, מאת Greg Ewing ‏< greg.ew...@canterbury.ac.nz>: > Rémi Lapeyre wrote: > > > You can make "inferences from the way things are used". But the > > comparison with maths stops here, you don’t make such inferences because > your > > object must be well defined before

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.

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

Re: [Python-ideas] Why operators are useful

2019-03-18 Thread Greg Ewing
Rémi Lapeyre wrote: You can make "inferences from the way things are used". But the comparison with maths stops here, you don’t make such inferences because your object must be well defined before you start using it. In maths texts it's very common to see things like 'Let y = f(x)...' where

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

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] ==

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

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

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

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

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,

Re: [Python-ideas] Add subprocess.Popen suspend() and resume()

2019-03-18 Thread Antoine Pitrou
Seems reasonable to me. Regards Antoine. On Mon, 18 Mar 2019 16:41:34 +0100 "Giampaolo Rodola'" wrote: > Hello, > I've been having these 2 implemented in psutil for a long time. On > POSIX these are convenience functions using os.kill() + SIGSTOP / > SIGCONT (the same as CTRL+Z / "fg"). On

[Python-ideas] Add subprocess.Popen suspend() and resume()

2019-03-18 Thread Giampaolo Rodola'
Hello, I've been having these 2 implemented in psutil for a long time. On POSIX these are convenience functions using os.kill() + SIGSTOP / SIGCONT (the same as CTRL+Z / "fg"). On Windows they use undocumented NtSuspendProcess and NtResumeProcess Windows APIs available since XP. The same approach

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

Re: [Python-ideas] Why operators are useful

2019-03-18 Thread Jimmy Girardet
Hi, Please let me share my story of non experienced python programmer. Last year I wanted to merge three dicts  for config stuff. I found very quickly the answer : a = {**b, **c, **d} Sadly I was working on python 3.3 and that was nos possible to use this syntax. I don't remember what I did

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

Re: [Python-ideas] Why operators are useful

2019-03-18 Thread Antoine Pitrou
On Mon, 18 Mar 2019 14:06:53 + Rhodri James wrote: > On 16/03/2019 12:01, Gustavo Carneiro wrote: > > Already been said, but might have been forgotten, but the new proposed > > syntax: > > > > new = a + b > > > > has to compete with the already existing syntax: > > > > new =

Re: [Python-ideas] Why operators are useful

2019-03-18 Thread Rhodri James
On 16/03/2019 12:01, Gustavo Carneiro wrote: Already been said, but might have been forgotten, but the new proposed syntax: new = a + b has to compete with the already existing syntax: new = {**a, **b} That's easy. Whether it's spelt with "+" or "|" or pretty much anything

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] Why operators are useful

2019-03-18 Thread Rémi Lapeyre
Le 17 mars 2019 à 02:01:51, Greg Ewing (greg.ew...@canterbury.ac.nz(mailto:greg.ew...@canterbury.ac.nz)) a écrit: > Richard Damon wrote: > > Rémi, I believe, is assuming in their example that by defining the field > > of mathematics being used, there is at least an implicit definition (if > > not

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]: > ...

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

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

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

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

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

[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

Re: [Python-ideas] New Data Structure - Non Well-Founded Dict

2019-03-18 Thread Jeff Allen
Stephanie: Welcome. The "Python idea" here is to allow a broader range of types as keys to a dictionary. The gap appears to be that certain types (like set) "don't work" as keys (or rather their identities not values work), but this is a misunderstanding. A set is mutable: it is as if, in an