[docs] [issue24243] behavior for finding an empty string is inconsistent with documentation

R. David Murray report at bugs.python.org
Wed May 20 16:00:55 CEST 2015


R. David Murray added the comment:

"If the slices indexes had to be in range, that would be inconsistent with the behavior of slicing"

No, it wouldn't.  Your slice example is two operations: the slice returns an empty string (because that's how the *substring* operation is defined to behave for an out-of-range slice), and *then* the search operation is called on it; but in the call with index arguments, the indicies are specifying the slice to search in using the slice semantics of the indicies, but that substring is invalid for the *search* operation.

I agree that the startswith/endswith difference between string a bytes looks like a bug, and that the bytes case looks to be the correct one, in terms of consistency with the other search operations.  Those operations are a bit different from the other search operations, though, so I could see it argued the other way.

The point is that the slice notation specifies how to compute the substring, but what happens if the substring is out of range depends on the *operation*.

----------
nosy: +r.david.murray

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue24243>
_______________________________________


More information about the docs mailing list