Re: [Python-ideas] Implementing a set of operation (+, /, - *) on dict consistent with linearAlgebrae

2018-10-31 Thread Kyle Lahnakoski
Julien, Personally, I would be able to use the module you are proposing to accumulate arbitrarily-named measures. I can not think of a use case for division, but it would be nice for completion.  I have made my own library that implements a small part of what you propose [1]. I was looking throu

[Python-ideas] Allow Context Managers to Support Suspended Execution

2018-10-31 Thread David Allemang
I do not think there is currently a good way for Context Managers to support suspended execution, as in await or yield. Both of these instructions cause the interpreter to leave the with block, yet no indication of this (temporary) exit or subsequent re-entrance is given to the context manager. If

Re: [Python-ideas] Add "default" kwarg to list.pop()

2018-10-31 Thread Chris Angelico
On Thu, Nov 1, 2018 at 7:46 AM Robert Vanden Eynde wrote: >> >> >> That said, though, you may well not need to go to that effort. What is >> being asked for here (if I'm not misreading) is a relatively simple >> enhancement to a method on a built-in type (or a small handful of >> types). If that g

Re: [Python-ideas] Add "default" kwarg to list.pop()

2018-10-31 Thread Robert Vanden Eynde
> > > That said, though, you may well not need to go to that effort. What is > being asked for here (if I'm not misreading) is a relatively simple > enhancement to a method on a built-in type (or a small handful of > types). If that garners reasonable support, the next step wouldn't be > a PEP, it'

Re: [Python-ideas] Add "default" kwarg to list.pop()

2018-10-31 Thread Michael Selik
On Wed, Oct 31, 2018 at 12:31 PM Chris Angelico wrote: > What is being asked for here (if I'm not misreading) is a relatively simple > enhancement to a method on a built-in type (or a small handful of > types). If that garners reasonable support, the next step wouldn't be > a PEP, it'd just go st

Re: [Python-ideas] Add "default" kwarg to list.pop()

2018-10-31 Thread Chris Angelico
On Thu, Nov 1, 2018 at 6:25 AM Robert Vanden Eynde wrote: > > Oooh, PEP463, you're reason with I switch to LBYL or write studpid try except > functions so much times. > > Oh and also the local assignement "let/where/statement" :D > > x = (y+1 where y = 3.14) because x = [y+1 for y in [3.14]][0] i

Re: [Python-ideas] Implementing a set of operation (+, /, - *) on dict consistent with linearAlgebrae

2018-10-31 Thread Robert Vanden Eynde
And with libraries like pip install funcoperators or pip install infix, you can even write it infix :D from funcoperators import infix @infix def superop(d1, sc): return {k: (v *superopp* sc) for k, v in d1.items()} print({'a': 8} *superop* 5) Le mer. 31 oct. 2018 à 18:35, Vladimir Filipovi

Re: [Python-ideas] Add "default" kwarg to list.pop()

2018-10-31 Thread Robert Vanden Eynde
Oooh, PEP463, you're reason with I switch to LBYL or write studpid try except functions so much times. Oh and also the local assignement "let/where/statement" :D x = (y+1 where y = 3.14) because x = [y+1 for y in [3.14]][0] is an overkill and ugly. Should I write a PEP even though I know it's go

Re: [Python-ideas] Add "default" kwarg to list.pop()

2018-10-31 Thread Michael Selik
On Wed, Oct 31, 2018 at 10:17 AM Eric Fahlgren wrote: > On Wed, Oct 31, 2018 at 2:42 AM Chris Angelico wrote: > >> https://www.python.org/dev/peps/pep-0463/ wants to say hi. >> > > That was exactly my reaction, too, and usually is whenever one of these > "add a default" or similar ideas pops up.

Re: [Python-ideas] Implementing a set of operation (+, /, - *) on dict consistent with linearAlgebrae

2018-10-31 Thread Vladimir Filipović
Julien, would I be correct if I summarized the changes you have in mind like this: for dictionaries d1 and d2, non-Mapping ("scalar") sc, binary operation ⊛, and unary operation 𝓊 (such as negation or abs()): d1 ⊛ sc == {k: (v ⊛ sc) for k, v in d1.items()} sc ⊛ d1 == {k: (sc ⊛ v) for k, v in d1.i

Re: [Python-ideas] Add "default" kwarg to list.pop()

2018-10-31 Thread Eric Fahlgren
On Wed, Oct 31, 2018 at 2:42 AM Chris Angelico wrote: > > https://www.python.org/dev/peps/pep-0463/ wants to say hi. > > That was exactly my reaction, too, and usually is whenever one of these "add a default" or similar ideas pops up. 463 should be re-examined, I was very hopeful when it went th

Re: [Python-ideas] Add "default" kwarg to list.pop()

2018-10-31 Thread Steven D'Aprano
On Wed, Oct 31, 2018 at 09:31:37PM +1100, Chris Angelico wrote: > > I don't think I would agree with a broad rule "anything that raises can > > return a default value" -- I don't think it makes sense to have, let's > > say, len(obj, default=2). But on a case-by-case basis, it works for me. > > An

Re: [Python-ideas] Add "default" kwarg to list.pop()

2018-10-31 Thread Antoine Pitrou
On Wed, 31 Oct 2018 00:44:55 +0100 "Giampaolo Rodola'" wrote: > Sorry in advance if this has been proposed in the past but I couldn't find > anything on python-ideas: > > >>> l = [] > >>> l.pop(default=1) > 1 > > FWIW my use case consists in reading entries from /proc/diskstats where > lines c

Re: [Python-ideas] Add "default" kwarg to list.pop()

2018-10-31 Thread Michel Desmoulin
+1 one this. And a list.get method has well, with a default value. Le 31/10/2018 à 00:44, Giampaolo Rodola' a écrit : Sorry in advance if this has been proposed in the past but I couldn't find anything on python-ideas:  >>> l = []  >>> l.pop(default=1) 1 FWIW my use case consists in reading e

Re: [Python-ideas] Add "default" kwarg to list.pop()

2018-10-31 Thread Antoine Pitrou
On Wed, 31 Oct 2018 02:25:25 +0200 Serhiy Storchaka wrote: > 31.10.18 01:44, Giampaolo Rodola' пише: > > Sorry in advance if this has been proposed in the past but I couldn't > > find anything on python-ideas: > > > > >>> l = [] > > >>> l.pop(default=1) > > 1 > > > > FWIW my use case cons

Re: [Python-ideas] Add "default" kwarg to list.pop()

2018-10-31 Thread Chris Angelico
On Wed, Oct 31, 2018 at 9:14 PM Steven D'Aprano wrote: > > On Wed, Oct 31, 2018 at 08:41:28PM +1100, Chris Angelico wrote: > > On Wed, Oct 31, 2018 at 8:24 PM Nicolas Rolin > > wrote: > > > > > > > > > As a user I always found a bit disurbing that dict pop method have a > > > default while list

Re: [Python-ideas] Add "default" kwarg to list.pop()

2018-10-31 Thread Steven D'Aprano
On Wed, Oct 31, 2018 at 08:41:28PM +1100, Chris Angelico wrote: > On Wed, Oct 31, 2018 at 8:24 PM Nicolas Rolin wrote: > > > > > > As a user I always found a bit disurbing that dict pop method have a > > default while list and set doesn't. > > While it is way more computationally easy to check we

Re: [Python-ideas] Add "default" kwarg to list.pop()

2018-10-31 Thread Chris Angelico
On Wed, Oct 31, 2018 at 8:24 PM Nicolas Rolin wrote: > > > As a user I always found a bit disurbing that dict pop method have a default > while list and set doesn't. > While it is way more computationally easy to check wether a list or a set is > empty that to check if a key is in a dict, it sti

Re: [Python-ideas] Add "default" kwarg to list.pop()

2018-10-31 Thread Robert Vanden Eynde
I think the same way about set.pop, list.pop. About .index I agree adding default= would make sense but that's not exactly the same thing as the others. Do we have somewhere else a place where a linear search already accepts a default= kwarg ? def index(self, x): for i,y in enumerate(self):

Re: [Python-ideas] Add "default" kwarg to list.pop()

2018-10-31 Thread Ron Reiter
I think l.pop() if l else None is good enough. I think it's pretty obvious that a developer means "Pop the list if the list is not empty, and return None if the list is empty ". - Ron [image: Facebook] [image: Twitter] [image

Re: [Python-ideas] Add "default" kwarg to list.pop()

2018-10-31 Thread Nicolas Rolin
As a user I always found a bit disurbing that dict pop method have a default while list and set doesn't. While it is way more computationally easy to check wether a list or a set is empty that to check if a key is in a dict, it still create a signature difference for no real reason (having a defaul