list.index(..) -> TypeError bug or feature?

Fredrik Lundh fredrik at effbot.org
Tue Feb 6 18:53:47 CET 2001


Pearu Peterson wrote:
> In Python 2.1a2 I get TypeError exception from list index() method even if
> the list contains given object:
>
> >>> from gmpy import mpz
> >>> a = [mpz(1),[]]
> >>> a.index([])
> Traceback (most recent call last):
>   File "<stdin>", line 1, in ?
> TypeError: coercion to gmpy.mpz type failed
>
> while in Python 2.0b2 it works:
>
> >>> a = [mpz(1),[]]
> >>> a.index([])
> 1

looks like mpz's coercion code doesn't work well under
2.1's new coercion model:

    http://python.sourceforge.net/peps/pep-0208.html

possibly when combined with the new comparision model:

    http://python.sourceforge.net/peps/pep-0207.html

I'll leave it to the PEP authors to figure out what's wrong
here (2.1, gmpy, or "sorry, you cannot do that")

Cheers /F





More information about the Python-list mailing list