This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author martin.panter
Recipients docs@python, martin.panter, swanson
Date 2015-05-20.12:27:04
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1432124825.33.0.978796634428.issue24243@psf.upfronthosting.co.za>
In-reply-to
Content
There are a few related issues here I think:

1. Empty string search: I think it is completely valid to be able to find an empty string inside another string, at least as long as the slice indexes are within range. Although I remember it was a bit of a revelation the first time I considered this. Anyway, the documentation should explicitly mention this case.

2. "".find("", 1, 0) -> -1: This is inconsistent with startswith() and slicing, but the only reasonable alternative would be to return 1, which would be a strange index for an empty string. Certainly needs documenting though.

3. starts/endswith() slice arguments: I think they should be described equivalently to find() etc. So “start” points to the first character, “end” points after the last character, negative indexes from the end, etc.

4. "".startswith("", 1, 0): This is True for str, and False for bytes, which is terribly inconsistent. My gut says both should be False, to match how find() works.

Some other related undocumented quirks:

>>> "abcd".count("")  # Infinity? End of the universe? No!
5
>>> "abcd".replace("", "_", 10)  # Might expect 10 underscores
'_a_b_c_d_'
>>> "abcd".split("", 10)  # Might expect a list of 11 strings
ValueError: empty separator
>>> "abcd".partition("")  # Why not ("", "", "abcd")?
ValueError: empty separator
History
Date User Action Args
2015-05-20 12:27:05martin.pantersetrecipients: + martin.panter, docs@python, swanson
2015-05-20 12:27:05martin.pantersetmessageid: <1432124825.33.0.978796634428.issue24243@psf.upfronthosting.co.za>
2015-05-20 12:27:05martin.panterlinkissue24243 messages
2015-05-20 12:27:04martin.pantercreate