Dan Snider <mr.assume.a...@gmail.com> added the comment:

So I also just happened to notice that the "documentation is wrong" for list, 
tuple, and collections.deque. They use use _PyEval_SliceIndexNotNone whch 
causes this:

>>> s = 'abcde'
>>> s.index('d', 0, None)
3
>>> [*s].index('d', None)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
    [*s].index('d', None)
TypeError: slice indices must be integers or have an __index__ method

In 3.6.0, that error message is:
    TypeError: slice indices must be integers or None or have an __index__ 
method

which means someone else was aware of this behavior and switched from 
_PyEval_SliceIndex to _PyEval_SliceIndexNotNone but didn't think these 
inconsistencies were inappropriate?

Anyway, I'll go ahead fix the docs later for accuracy's sake, but I'd much 
rather update operator.indexOf to use a new abstract api function: 
"PySequence_IndexOf" or some such, which is also capable of handling starting 
from the tail like str.rindex. 

If that's something that could be done, after I finish the Python prototype of 
this sequence ChainMap analog and rewrite it in C, I'll have made my own 
abstract sequence index function which I'd happily share.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue34848>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to