On 22/03/2020 22:25, Dennis Sweeney wrote:
Here's an updated version.
Online: https://www.python.org/dev/peps/pep-0616/ Source: https://raw.githubusercontent.com/python/peps/master/pep-0616.rst
Changes: - More complete Python implementation to match what the type checking in the C implementation would be - Clarified that returning ``self`` is an optimization - Added links to past discussions on Python-Ideas and Python-Dev - Specified ability to accept a tuple of strings - Shorter abstract section and fewer stdlib examples - Mentioned - Typo and formatting fixes
I didn't change the name because it didn't seem like there was a strong consensus for an alternative yet. I liked the suggestions of ``dropprefix`` or ``removeprefix``.
All the best, Dennis _______________________________________________
Proofreading: it would not be obvious for users to have to call 'foobar'.cutprefix(('foo,)) for the common use case of a single prefix. Missing single quote after the last foo.
s = 'foobar' * 100 + 'bar' prefixes = ('bar', 'foo') while len(s) != len(s := s.cutprefix(prefixes)): pass s 'bar'
or the more obvious and readable alternative:
s = 'foo' * 100 + 'bar' prefixes = ('bar', 'foo') while s.startswith(prefixes): s = s.cutprefix(prefixes) s 'bar'
Er no, in both these examples s is reduced to an empty string. Best wishes Rob Cliffe