UserString.rindex raises a TypeError when its sub argument is a UserString object. This behavior is inconsistent with UserString.rfind and most other string methods.
For reference, __contains__, count, find and replace were fixed in 98b349f. But rfind was only fixed in da2ecaf, 2.5 years later. index and rindex were missed again.
Activity
picnixz commented on Nov 2, 2025
I can see that there is an isinstance check in rfind. It's legitimate to assume that we need one in rindex.
serhiy-storchaka commented on Nov 3, 2025
For reference, __contains__, count, find and replace were fixed in 98b349f. But rfind was only fixed in da2ecaf, 2.5 years later. index and rindex were missed again.
gh-140911: Ensure that UserString.index() and UserString.rindex() acc…
pythongh-140911: Ensure that UserString.index() and UserString.rindex…
pythongh-140911: Ensure that UserString.index() and UserString.rindex…
[3.13] gh-140911: Ensure that UserString.index() and UserString.rinde…
[3.14] gh-140911: Ensure that UserString.index() and UserString.rinde…
pythongh-140911: Ensure that UserString.index() and UserString.rindex…
pythongh-140911: Ensure that UserString.index() and UserString.rindex…