[Python-Dev] Re: PyNumber_Check() (original) (raw)

Guido van Rossum guido@python.org
Mon, 18 Nov 2002 12:24:42 -0500


gvanrossum@projects.sourceforge.net wrote: > *** NEWS 18 Nov 2002 16:19:39 -0000 1.526 > --- NEWS 18 Nov 2002 16:27:16 -0000 1.527 > *************** > *** 694,698 **** > - PyNumberCheck() now returns true for string and unicode objects. > This is a result of these types having a partially defined > ! tpasnumber slot. > > - The string object's layout has changed: the pointer member > --- 694,700 ---- > - PyNumberCheck() now returns true for string and unicode objects. > This is a result of these types having a partially defined > ! tpasnumber slot. (This is not a feature, but an indication that > ! PyNumbercheck() is not very useful to determine numeric behavior. > ! It may be deprecated.)

Perhaps PyNumberCheck() should check that at least one of nbint, nblong, nbfloat is available (in addition to the tpasnumber slot) ?!

No, I think PyNumber_Check() should be deprecated. I don't think there's a valid use case for it. If you really want a fuzzy definition like "at least one of nb_int, nb_long, nb_float is available", you can test for that yourself -- IMO that doesn't really make it a number.

PyNumber_Check() comes from an old era, when the presence or absence of the as_number "extension" to the type object was thought to be useful. If I had to do it over, I wouldn't provide PyNumber_Check() at all (nor PySequence_Check() nor PyMapping_Check()).

--Guido van Rossum (home page: http://www.python.org/~guido/)