[New-bugs-announce] [issue23757] tuple function gives wrong answer when called on list subclass with custom __iter__

David MacIver report at bugs.python.org
Tue Mar 24 09:42:29 CET 2015


New submission from David MacIver:

Converting a list to a tuple appears to have an optimisation that is wrong in the presence of subclassing to override __iter__. It ignores the user defined iter and uses the normal list one. I've attached a file with a test case to demonstrate this.

I've verified this on both python 2.7 and python 3.4. It's presumably also the case on everything in between.

This was found because it caused a bug with a type that pytz uses, which lazily populates the list on iteration: https://bugs.launchpad.net/pytz/+bug/1435617

----------
components: Library (Lib)
files: listwithiter.py
messages: 239098
nosy: David MacIver
priority: normal
severity: normal
status: open
title: tuple function gives wrong answer when called on list subclass with custom __iter__
versions: Python 2.7, Python 3.4
Added file: http://bugs.python.org/file38663/listwithiter.py

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue23757>
_______________________________________


More information about the New-bugs-announce mailing list