[issue17576] PyNumber_Index() is not int-subclass friendly (or operator.index() docos lie)
Barry A. Warsaw
report at bugs.python.org
Sat Mar 30 01:39:42 CET 2013
Barry A. Warsaw added the comment:
On Mar 30, 2013, at 12:29 AM, Eric Snow wrote:
>Would it be okay to do a check on __index__ after the PyLong_Check()
>succeeds? Something like this:
>
> if (PyLong_Check(item) &&
> item->ob_type->tp_as_number->nb_index == PyLong_Type.tp_as_number->nb_index) {
> Py_INCREF(item);
> return item;
> }
>
>This is something Nick and I were talking about at the sprints regarding fast
>paths in the abstract API (for mappings and sequences in our case).
I think that would work, yes. With this extra check, overriding __index__()
in the subclass should fail this condition and fall back to the
PyIndex_Check() clause.
----------
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue17576>
_______________________________________
More information about the Python-bugs-list
mailing list