This issue tracker has been migrated to GitHub ,
and is currently read-only.
For more information,
see the GitHub FAQs in the Python's Developer Guide.
Created on 2012年06月07日 05:23 by Julian, last changed 2022年04月11日 14:57 by admin. This issue is now closed.
| Messages (3) | |||
|---|---|---|---|
| msg162457 - (view) | Author: Julian Berman (Julian) * | Date: 2012年06月07日 05:23 | |
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. |
|||
| msg162458 - (view) | Author: Julian Berman (Julian) * | Date: 2012年06月07日 05:26 | |
Oh, and, with apologies for the double post, tuple does the same, while set, dict, collections.deque do not. |
|||
| msg162477 - (view) | Author: Benjamin Peterson (benjamin.peterson) * (Python committer) | Date: 2012年06月07日 16:59 | |
It's an optimization. No one says we can't call __len__(). |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:57:31 | admin | set | github: 59228 |
| 2012年06月07日 19:23:32 | r.david.murray | set | status: open -> closed resolution: not a bug stage: resolved |
| 2012年06月07日 16:59:35 | benjamin.peterson | set | nosy:
+ benjamin.peterson messages: + msg162477 |
| 2012年06月07日 05:26:01 | Julian | set | messages: + msg162458 |
| 2012年06月07日 05:23:12 | Julian | create | |