9 Aug
2021
9 Aug
'21
3:53 a.m.
On Mon, Aug 9, 2021 at 1:42 PM <fgallaire@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