difference between `x in list` and `list.index(x)` for instances of a new-style class
Gabriel Genellina
gagsl-py2 at yahoo.com.ar
Sun Dec 30 08:55:49 EST 2007
On 30 dic, 06:24, Riccardo Murri <riccardo.mu... at gmail.com> wrote:
> bpgbai... at gmail.com writes:
>
> >> (Pydb) p graph == self.base[27]
> >> True
> >> (Pydb) p graph in self.base
> >> True
> >> (Pydb) self.base.index(graph)
> >> *** ValueError: list.index(x): x not in list
> > Looking at the source for both methods, they only
> > use the __eq__ operator, but there is a slight difference: while one
> > evaluates list[i]==x, the other reverses the operands. If your __eq__
> > is not reflexive, that could explain the difference.
>
> That was indeed the reason: a bug in Graph.__eq__ broke reflexivity in
> certain cases.
Combined with some other WTF bugs I've found at work, lately I feel
more like a detective than a software developer :)
--
Gabriel Genellina
More information about the Python-list
mailing list