funnel icon indicating copy to clipboard operation
funnel copied to clipboard

Use `str.removeprefix` and `str.removesuffix` where relevant

Open jace opened this issue 2 years ago • 0 comments
trafficstars

A recurring pattern:

text: str
if text.startswith('prefix'):
    text = text[len('prefix'):]

Python 3.9 has two new methods on str, removeprefix and removesuffix, that collapse these into a single line. They are safer as we usually hardcode the value of len(prefix) and linters will not catch a discrepancy.

jace avatar Sep 27 '23 07:09 jace