[Python-Dev] list.extend

Tim Peters tim.one@comcast.net
Fri, 28 Jun 2002 01:20:17 -0400

[David Abrahams]
> As long as I'm eyeballin' (and you're thankin'), I notice in PyInt_AsLong:
>  if (op == NULL || (nb = op->ob_type->tp_as_number) == NULL ||
>      nb->nb_int == NULL) {
>     PyErr_SetString(PyExc_TypeError, "an integer is required");
>   return -1;
>  }
> But really, an integer isn't required; Any type with a
> tp_as_number section and a conversion to int will do. Should the
> error say "a numeric type convertible to int is required"?

I'll leave it up to Fred, but I don't think so.  The suggestion is wordier,
would be wordier still if converted to the more accurate "an object of a
numeric type convertible to int is required", and even then is not, IMO,
more likely to be of real help when this error triggers.  If you want to
change it, be sure to hunt down all the related ones too; e.g.,

>>> class C: pass
>>> range(12)[C()]
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
TypeError: list indices must be integers

BTW, most places that call PyInt_AsLong() either do so conditionally upon
the success of a PyInt_Check(), or replace the exception raised when it
returns -1 with an error.  Offhand I wasn't even able to provoke the msg in