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?

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

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.

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