On 22Mar2020 08:10, Ivan Pozdeev firstname.lastname@example.org wrote:
On 22.03.2020 7:46, Steven D'Aprano wrote:
On Sun, Mar 22, 2020 at 06:57:52AM +0300, Ivan Pozdeev via Python-Dev wrote:
Does it need to be separate methods?
Overloading a single method to do two dissimilar things is poor design.
They are similar. We're removing stuff from an edge in both cases. The only difference is whether input is treated as a character set or as a raw substring.
That is not the only difference. strip() does not just remove a character from the set provided (as a str). It removes as many of them as there are; that is why "foo.ext".strip(".ext") can actually be quite misleading to someone looking for a suffix remover - it often looks like it did the right thing.
By contrast, cutprefix/cutsuffix (or stripsuffix, whatever) remove only _one_ instance of the affix.
To my mind they are quite different, which is the basis of my personal dislike of reusing the word "strip". Just extending "strip()" with a funky new affix mode would be even worse, since it can _still_ be misleading if the caller omited the special mode.
Cheers, Cameron Simpson email@example.com