]> granicus.if.org Git - python/commitdiff
Make PyNumber_Check() a bit more careful, since all sorts of things
authorGuido van Rossum <guido@python.org>
Tue, 18 Feb 2003 16:36:28 +0000 (16:36 +0000)
committerGuido van Rossum <guido@python.org>
Tue, 18 Feb 2003 16:36:28 +0000 (16:36 +0000)
now have tp_as_number.  Check for nb_int or nb_float.

Misc/NEWS
Objects/abstract.c

index 5e0bad46cfd385191216d2377a74c198140a7ff8..19752f03c6e15e83854fd69f54e0d165260be906 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -89,6 +89,10 @@ Core and builtins
 Extension modules
 -----------------
 
+- operator.isNumberType() now checks that the object has a nb_int or
+  nb_float slot, rather than simply checking whether it has a non-NULL
+  tp_as_number pointer.
+
 - The imp module now has ways to acquire and release the "import
   lock": imp.acquire_lock() and imp.release_lock().  Note: this is a
   reentrant lock, so releasing the lock only truly releases it when
@@ -318,6 +322,10 @@ Build
 C API
 -----
 
+- PyNumber_Check() now checks that the object has a nb_int or nb_float
+  slot, rather than simply checking whether it has a non-NULL
+  tp_as_number pointer.
+
 - A C type that inherits from a base type that defines tp_as_buffer
   will now inherit the tp_as_buffer pointer if it doesn't define one.
   (SF #681367)
index c18d5e7f78ff7b8d30b0a5e182ef25f4d24132ea..b4fbd32a872c4153fcbafae97bc79618fdba09ac 100644 (file)
@@ -308,7 +308,9 @@ int PyObject_AsWriteBuffer(PyObject *obj,
 int
 PyNumber_Check(PyObject *o)
 {
-       return o && o->ob_type->tp_as_number;
+       return o && o->ob_type->tp_as_number &&
+              (o->ob_type->tp_as_number->nb_int ||
+               o->ob_type->tp_as_number->nb_float);
 }
 
 /* Binary operators */