Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6921eca

Browse files
committed
Make PyNumber_Check() a bit more careful, since all sorts of things
now have tp_as_number. Check for nb_int or nb_float.
1 parent 55dc26c commit 6921eca

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

Misc/NEWS

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ Core and builtins
8989
Extension modules
9090
-----------------
9191

92+
- operator.isNumberType() now checks that the object has a nb_int or
93+
nb_float slot, rather than simply checking whether it has a non-NULL
94+
tp_as_number pointer.
95+
9296
- The imp module now has ways to acquire and release the "import
9397
lock": imp.acquire_lock() and imp.release_lock(). Note: this is a
9498
reentrant lock, so releasing the lock only truly releases it when
@@ -318,6 +322,10 @@ Build
318322
C API
319323
-----
320324

325+
- PyNumber_Check() now checks that the object has a nb_int or nb_float
326+
slot, rather than simply checking whether it has a non-NULL
327+
tp_as_number pointer.
328+
321329
- A C type that inherits from a base type that defines tp_as_buffer
322330
will now inherit the tp_as_buffer pointer if it doesn't define one.
323331
(SF #681367)

Objects/abstract.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,9 @@ int PyObject_AsWriteBuffer(PyObject *obj,
308308
int
309309
PyNumber_Check(PyObject *o)
310310
{
311-
return o && o->ob_type->tp_as_number;
311+
return o && o->ob_type->tp_as_number &&
312+
(o->ob_type->tp_as_number->nb_int ||
313+
o->ob_type->tp_as_number->nb_float);
312314
}
313315

314316
/* Binary operators */

0 commit comments

Comments
 (0)