Re: [Python-ideas] A suggestion for a do...while loop

2017-06-25 Thread Nick Coghlan
On 26 June 2017 at 10:25, Rob Cliffe wrote: > > > On 25/06/2017 12:58, Markus Meskanen wrote: >> >> I'm a huge fan of the do...while loop in other languages, and it would >> often be useful in Python too, when doing stuff like: >> >> while True: >> password =

Re: [Python-ideas] + operator on generators

2017-06-25 Thread Steven D'Aprano
On Sun, Jun 25, 2017 at 02:06:54PM +0200, lucas via Python-ideas wrote: > What about providing something like the following: > > a = (n for n in range(2)) > b = (n for n in range(2, 4)) > tuple(a + b) # -> 0 1 2 3 As Serhiy points out, this is going to conflict with existing use of

Re: [Python-ideas] + operator on generators

2017-06-25 Thread Wes Turner
On Sunday, June 25, 2017, Danilo J. S. Bellini wrote: > On Sun, Jun 25, 2017 at 3:06 PM, lucas via Python-ideas < > python-ideas@python.org > > wrote: > >> I often use generators, and itertools.chain on them. >>

Re: [Python-ideas] Allow function to return multiple values

2017-06-25 Thread Mikhail V
On 26 June 2017 at 01:14, rym...@gmail.com wrote: > IIRC I'm pretty sure the OP just didn't know about the existence of tuple > unpacking and the ability to use that to return multiple values. > Can be so, though it was not quite clear. The original OP's example function

Re: [Python-ideas] A suggestion for a do...while loop

2017-06-25 Thread Rob Cliffe
On 25/06/2017 12:58, Markus Meskanen wrote: I'm a huge fan of the do...while loop in other languages, and it would often be useful in Python too, when doing stuff like: while True: password = input() if password == ...: break [...]I suggest [...] do: password =

Re: [Python-ideas] Improving Catching Exceptions

2017-06-25 Thread Rob Cliffe
On 24/06/2017 11:03, Steven D'Aprano wrote: On Sat, Jun 24, 2017 at 01:02:55PM +1200, Greg Ewing wrote: In any case, this doesn't address the issue raised by the OP, which in this example is that if the implementation of bah.__getitem__ calls something else that raises an IndexError, there's

Re: [Python-ideas] Allow function to return multiple values

2017-06-25 Thread rym...@gmail.com
IIRC I'm pretty sure the OP just didn't know about the existence of tuple unpacking and the ability to use that to return multiple values. -- Ryan (ライアン) Yoko Shimomura, ryo (supercell/EGOIST), Hiroyuki Sawano >> everyone elsehttp://refi64.com On Jun 25, 2017 at 6:09 PM, > wrote: joannah

Re: [Python-ideas] Allow function to return multiple values

2017-06-25 Thread Mikhail V
joannah nanjekye wrote: > [...] > >Today I was writing an example snippet for the book and needed to write a >function that returns two values something like this: > >def return_multiplevalues(num1, num2): > return num1, num2 > > I noticed that this actually returns a tuple of the values

Re: [Python-ideas] Reducing collisions in small dicts/sets

2017-06-25 Thread Tim Peters
Two bits of new info: first, it's possible to get the performance of "double" without division, at least via this way: """ # Double hashing using Fibonacci multiplication for the increment. This # does about as well as `double`, but doesn't require division. # # The multiplicative constant

Re: [Python-ideas] + operator on generators

2017-06-25 Thread Danilo J. S. Bellini
On Sun, Jun 25, 2017 at 3:06 PM, lucas via Python-ideas < python-ideas@python.org> wrote: > I often use generators, and itertools.chain on them. > What about providing something like the following: > > a = (n for n in range(2)) > b = (n for n in range(2, 4)) > tuple(a + b) # -> 0 1 2

Re: [Python-ideas] Runtime types vs static types

2017-06-25 Thread Lucas Wiman
After rereading Koos' OP, I can now see that he was referring to a different kind of runtime type checking than I am interested in. There was a distinction I was unaware the core typing devs make between "typing-style types" and "classes" that I'll discuss further in the typing repo itself.

Re: [Python-ideas] Runtime types vs static types

2017-06-25 Thread Koos Zevenhoven
On Sun, Jun 25, 2017 at 8:47 PM, Lucas Wiman wrote: > > ​Yes, but then `isinstance(tuple(range(100)), Tuple[int, ...])` > would be a difficult case. > > Yes, many methods on million-element tuples are slow. :-) > > Python usually chooses the more intuitive behavior

Re: [Python-ideas] Runtime types vs static types

2017-06-25 Thread Lucas Wiman
> ​Yes, but then `isinstance(tuple(range(100)), Tuple[int, ...])` would be a difficult case. Yes, many methods on million-element tuples are slow. :-) Python usually chooses the more intuitive behavior over the faster behavior when there is a choice. IIUC, the objections don't have anything

Re: [Python-ideas] + operator on generators

2017-06-25 Thread Koos Zevenhoven
On Sun, Jun 25, 2017 at 3:06 PM, lucas via Python-ideas < python-ideas@python.org> wrote: > I often use generators, and itertools.chain on them. > What about providing something like the following: > > a = (n for n in range(2)) > b = (n for n in range(2, 4)) > tuple(a + b) # -> 0 1 2

Re: [Python-ideas] Improving Catching Exceptions

2017-06-25 Thread Steven D'Aprano
On Sat, Jun 24, 2017 at 11:45:25PM +1000, Nick Coghlan wrote: > While I used to think that, I'm no longer sure it's true, as it seems > to me that a `contextlib.convert_exception` context manager could help > with both of them. Here is a recipe for such a context manager which is also useable

Re: [Python-ideas] Runtime types vs static types

2017-06-25 Thread Koos Zevenhoven
On Sun, Jun 25, 2017 at 7:13 PM, Lucas Wiman wrote: [...] > >>> from typing import * > >>> isinstance(0, Union[int, float]) > Traceback (most recent call last): > File "", line 1, in > File "/Users/lucaswiman/.pyenv/versions/3.6/lib/python3.6/typing.py", > line 767,

Re: [Python-ideas] Runtime types vs static types

2017-06-25 Thread Lucas Wiman
> > For some background on the removal of __instancecheck__, check the linked > issues here: > Thanks for the reference (the most relevant discussion starts here ). That said, I think I totally disagree with the underlying

Re: [Python-ideas] + operator on generators

2017-06-25 Thread Stephan Houben
I would like to add that for example numpy ndarrays are iterables, but they have an __add__ with completely different semantics, namely element-wise ( numerical) addition. So this proposal would conflict with existing libraries with iterable objects. Stephan Op 25 jun. 2017 2:51 p.m. schreef

Re: [Python-ideas] A suggestion for a do...while loop

2017-06-25 Thread Todd
On Jun 25, 2017 07:58, "Markus Meskanen" wrote: I'm a huge fan of the do...while loop in other languages, and it would often be useful in Python too, when doing stuff like: while True: password = input() if password == ...: break I've seen the pep 315

Re: [Python-ideas] Runtime types vs static types

2017-06-25 Thread rym...@gmail.com
For some background on the removal of __instancecheck__, check the linked issues here: https://github.com/python/typing/issues/135 -- Ryan (ライアン) Yoko Shimomura, ryo (supercell/EGOIST), Hiroyuki Sawano >> everyone elsehttp://refi64.com On Jun 25, 2017 at 8:11 AM, > wrote: On Sat, Jun 24,

Re: [Python-ideas] Runtime types vs static types

2017-06-25 Thread Koos Zevenhoven
On Sat, Jun 24, 2017 at 11:30 PM, Lucas Wiman wrote: > ​ > On Sat, Jun 24, 2017 at 12:42 PM, Koos Zevenhoven > wrote: > >> There has been some discussion here and there concerning the differences >> between runtime types and static types (mypy etc.).

Re: [Python-ideas] + operator on generators

2017-06-25 Thread Serhiy Storchaka
25.06.17 15:06, lucas via Python-ideas пише: I often use generators, and itertools.chain on them. What about providing something like the following: a = (n for n in range(2)) b = (n for n in range(2, 4)) tuple(a + b) # -> 0 1 2 3 This, from user point of view, is just as how

[Python-ideas] + operator on generators

2017-06-25 Thread lucas via Python-ideas
Hello ! I often use generators, and itertools.chain on them. What about providing something like the following: a = (n for n in range(2)) b = (n for n in range(2, 4)) tuple(a + b) # -> 0 1 2 3 This, from user point of view, is just as how the __add__ operator works on lists and

Re: [Python-ideas] A suggestion for a do...while loop

2017-06-25 Thread Serhiy Storchaka
25.06.17 14:58, Markus Meskanen пише: I'm a huge fan of the do...while loop in other languages, and it would often be useful in Python too, when doing stuff like: while True: password = input() if password == ...: break In this particular case you could write: for

[Python-ideas] A suggestion for a do...while loop

2017-06-25 Thread Markus Meskanen
I'm a huge fan of the do...while loop in other languages, and it would often be useful in Python too, when doing stuff like: while True: password = input() if password == ...: break I've seen the pep 315 which got rejected, and I believe these two suggestions were mostly focused