[issue23204] list.index and rest of list methods disagree if a value is in the list if it's mutated during the call

Devin Jeanpierre report at bugs.python.org
Fri Jan 9 08:25:48 CET 2015


New submission from Devin Jeanpierre:

>>> class AppendOnUnequal(object):
...     def __init__(self, append_to):
...         self.append_to = append_to
...     def __eq__(self, other):
...         if self is other:
...             return True
...         self.append_to.append(self)
...         return False
... 
>>> L = [1]; AppendOnUnequal(L) in L
True
>>> L = [1]; L.count(AppendOnUnequal(L))
1
>>> L = [1]; L.remove(AppendOnUnequal(L))
>>> L = [1]; L.index(AppendOnUnequal(L))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: <__main__.AppendOnUnequal object at 0x7f2562d071d0> is not in list


.index() is the only odd one out here. Looks like a bug to me.

----------
components: Interpreter Core
messages: 233721
nosy: Devin Jeanpierre
priority: normal
severity: normal
status: open
title: list.index and rest of list methods disagree if a value is in the list if it's mutated during the call
type: behavior
versions: Python 2.7, Python 3.4, Python 3.5, Python 3.6

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


More information about the Python-bugs-list mailing list