Message326746
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. |
|
Date |
User |
Action |
Args |
2018-09-30 20:54:25 | bup | set | recipients:
+ bup, rhettinger, docs@python, serhiy.storchaka |
2018-09-30 20:54:25 | bup | set | messageid: <1538340865.05.0.545547206417.issue34848@psf.upfronthosting.co.za> |
2018-09-30 20:54:25 | bup | link | issue34848 messages |
2018-09-30 20:54:24 | bup | create | |
|