New submission from Julian Berman <[email protected]>:
The following code raises an unexpected exception:
class Foo(object):
def __len__(self):
raise Exception()
def __iter__(self):
return iter([])
list(Foo())
In the optimizations being done in listextend, it appears len is getting called
first for some reason (sorry, haven't gotten a chance to step through it
carefully yet).
Tangentially, PyPy (correctly I guess) throws no such exception.
----------
components: Interpreter Core
messages: 162457
nosy: Julian
priority: normal
severity: normal
status: open
title: listextend (and therefore list.extend and list.__init__) peek at len
before iter
type: behavior
versions: Python 2.7, Python 3.2, Python 3.3, Python 3.4
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue15023>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com