> that can be used (eg) for indexing

Even without it being used in as complicated a way as that it's *still* not
backward compatible because of the trivial case, as foo.endswith("") is
True.

On Sun, Aug 8, 2021 at 11:55 PM Chris Angelico <ros...@gmail.com> wrote:

> On Mon, Aug 9, 2021 at 1:42 PM <fgalla...@gmail.com> wrote:
> >
> > This is a proposal to change the behaviour of the startswith() and
> > endswith() methods for str, bytes and bytearray objects, making them
> > return the matched value instead of the True boolean.
>
> Unfortunately this would break backward compatibility, since it's
> currently guaranteed that they return precisely True or False, and
> that can be used (eg) for indexing. To maintain that, you'd have to
> create new methods which return the matched value or None (and can
> then define startswith/endswith as the boolification of that). For
> instance:
>
> domain.findsuffix((".fr", ".com", ".org"))
>
> ChrisA
> _______________________________________________
> Python-ideas mailing list -- python-ideas@python.org
> To unsubscribe send an email to python-ideas-le...@python.org
> https://mail.python.org/mailman3/lists/python-ideas.python.org/
> Message archived at
> https://mail.python.org/archives/list/python-ideas@python.org/message/722CDS6W3FKLPWF4TBGUBHOL2RA5LZUV/
> Code of Conduct: http://python.org/psf/codeofconduct/
>
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/JDE22XCNDPDQQRF3FMTS33TFVJ7MLOFY/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to