Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Make PyNumber_Check() returning 1 for index integers.
  • Loading branch information
serhiy-storchaka committed Feb 22, 2019
commit b0aa18dc8cdcdacae0b3bdc6872653a626d7da51
3 changes: 3 additions & 0 deletions Doc/c-api/number.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ Number Protocol
Returns ``1`` if the object *o* provides numeric protocols, and false otherwise.
This function always succeeds.

.. versionchanged:: 3.8
Returns ``1`` if *o* is an index integer.


.. c:function:: PyObject* PyNumber_Add(PyObject *o1, PyObject *o2)

Expand Down
3 changes: 2 additions & 1 deletion Doc/whatsnew/3.8.rst
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,8 @@ Build and C API Changes
:meth:`~object.__int__`, if available. The deprecation warning will be
emitted for objects with the ``__int__()`` method but without the
``__index__()`` method (like :class:`~decimal.Decimal` and
:class:`~fractions.Fraction`).
:class:`~fractions.Fraction`). :c:func:`PyNumber_Check` will now return
``1`` for objects implementing ``__index__()``.
(Contributed by Serhiy Storchaka in :issue:`36048`.)


Expand Down
5 changes: 3 additions & 2 deletions Objects/abstract.c
Original file line number Diff line number Diff line change
Expand Up @@ -759,8 +759,9 @@ int
PyNumber_Check(PyObject *o)
{
return o && o->ob_type->tp_as_number &&
(o->ob_type->tp_as_number->nb_int ||
o->ob_type->tp_as_number->nb_float);
(o->ob_type->tp_as_number->nb_index ||
o->ob_type->tp_as_number->nb_int ||
o->ob_type->tp_as_number->nb_float);
}

/* Binary operators */
Expand Down