On Fri, Mar 20, 2020 at 3:28 PM Victor Stinner <[email protected]> wrote:

> > The builtin ``str`` class will gain two new methods with roughly the
> > following behavior::
> >
> >     def cutprefix(self: str, pre: str, /) -> str:
> >         if self.startswith(pre):
> >             return self[len(pre):]
> >         return self[:]
>

I tend to be mistrustful of code that tries to guess the best thing to do,
when something expected isn't found.

How about:

def cutprefix(self: str, pre: str, raise_on_no_match: bool=False, /) -> str:
    if self.startswith(pre):
        return self[len(pre):]
    if raise_on_no_match:
        raise ValueError('prefix not found')
    return self[:]
_______________________________________________
Python-Dev mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/[email protected]/message/NYMLVK35CVNWUL6OWZDB2CRA5W2HPMIH/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to