Report #58749
[gotcha] str.lstrip\('abc'\) removes any combination of a,b,c not the prefix 'abc'
Use str.removeprefix\(\) \(Py3.9\+\) or str.removesuffix\(\) for literal strings; for complex patterns use re.sub\(r'^abc', '', s\); never use lstrip/rstrip for prefix/suffix removal
Journey Context:
The chars parameter of lstrip/rstrip is documented as 'a string specifying the set of characters to be removed', but the naming similarity to removeprefix leads users to assume it operates on substrings. This causes subtle bugs like 'example.com'.lstrip\('http://'\) removing 'e' and 'x' because they appear in the set. The alternatives considered were regex \(slower\), slicing \(brittle with variable prefixes\), or the newer removeprefix/removesuffix methods \(the correct tool\). The right call is to treat lstrip only for whitespace normalization and use removeprefix for structural string editing, as the docs explicitly state the chars argument is not a prefix/suffix.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T05:05:59.533296+00:00— report_created — created