Hi Dennis,

Thanks for the updated PEP, it looks way better! I love the ability to
pass a tuple of strings ;-)

--

The behavior of tuple containing an empty string is a little bit surprising.

cutsuffix("Hello World", ("", " World")) returns "Hello World",
whereas cutsuffix("Hello World", (" World", "")) returns "Hello".

cutprefix() has a the same behavior: the first empty strings stops the
loop and returns the string unchanged.

I would prefer to raise ValueError("empty separator") to avoid any
risk of confusion. I'm not sure that str.cutprefix("") or
str.cutsuffix("") does make any sense.

"abc".startswith("") and "abc".startswith(("", "a")) are true, but
that's fine since startswith() doesn't modify the string. Moreover, we
cannot change the behavior now :-) But for new methods, we can try to
design them correctly to avoid any risk of confusion.

--

It reminds me https://bugs.python.org/issue28029: "".replace("", s, n)
now returns s instead of an empty string for all non-zero n. The
behavior changes in Python 3.9.

There are also discussions about "abc".split("") and
re.compile("").split("abc"). str.split() raises ValueError("empty
separator") whereas re.split returns ['', 'a', 'b', 'c', ''] which can
be (IMO) surprising.

See also https://bugs.python.org/issue28937 "str.split(): allow
removing empty strings (when sep is not None)".

Note: on the other wise, str.strip("") is accepted and returns the
string unmodified. But this method doesn't accept a tuple of
substrings. It's different  than cutprefix/cutsuffix.

Victor
-- 
Night gathers, and now my watch begins. It shall not end until my death.
_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/JF22AARPSQSRNFOIAHEILIBDNMSGMYWA/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to