[New-bugs-announce] [issue15023] listextend (and therefore list.extend and list.__init__) peek at len before iter

Julian Berman report at bugs.python.org
Thu Jun 7 07:23:12 CEST 2012


New submission from Julian Berman <Julian+Python.org at GrayVines.com>:

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 <report at bugs.python.org>
<http://bugs.python.org/issue15023>
_______________________________________


More information about the New-bugs-announce mailing list