On 25Mar2020 08:14, Paul Moore <p.f.mo...@gmail.com> wrote:
[...] The issue for me is how the function
should behave with a list of affixes if one is a prefix of another,
e.g.,removeprefix(('Test', 'Tests')). The empty string case is just
one form of that. The behaviour should be defined clearly, and while I
imagine "always remove the longest" is the "obvious" sensible choice,
I am fairly certain there will be other opinions :-) So deferring the
decision for now until we have more experience with the single-affix
form seems perfectly reasonable.

I'd like to preface this with "I'm fine to implement multiple affixes later, if at all". That said:

To me "first match" is the _only_ sensible choice. "longest match" can always be implemented with a "first match" function by sorting on length if desired.

Also, "longest first" requires the implementation to do a prescan of the supplied affixes whereas "first match" lets the implementation just iterate over the choices as supplied.

I'm beginning to think I must again threaten my partner's anecdote about Netscape Proxy's rule system, which prioritised rules by the lexical length of their regexp, not their config file order of appearance. That way lies (and, indeeed, lay) madness.

Cameron Simpson <c...@cskk.id.au>
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
Message archived at 
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to