On 11/23/2014 04:15 PM, Chris Angelico wrote:
On Mon, Nov 24, 2014 at 5:28 AM, Ron Adam<ron3...@gmail.com>  wrote:
>With the passage of the PEP, it will change what is different about them
>once it's in full effect.  The stop hack won't work in both, and you may get
>a RuntimeError in generator expressions where you would get StopIteration in
>list-comps.  (Is this correct?)
"them" being list comps and generator expressions?

Yes

The stop hack won't work in either (currently it does work in
genexps), but you'd get a different exception type if you attempt it.
This is correct. It's broadly similar to this distinction:

>>>{1:2,3:4}[50]
Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
KeyError: 50
>>>[1,2,3,4][50]
Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
IndexError: list index out of range

Comprehensions insert/append items, so you wouldn't get those unless you are reading from another object and would bubble out of generators too. Which is good because it's most likely an error that needs fixing.

In both lists and dicts, you can't look up something that isn't there.
But you get a slightly different exception type (granted, these two do
have a common superclass) depending on the exact context. But the
behaviour will be effectively the same.

I think the difference is very specific to StopIteration.

And I think we need to wait and see what happens in real code.

Cheers,
   Ron

_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to