-
-
Notifications
You must be signed in to change notification settings - Fork 33.5k
Closed
Labels
3.13bugs and security fixesbugs and security fixes3.14bugs and security fixesbugs and security fixes3.15new features, bugs and security fixesnew features, bugs and security fixeseasystdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
Bug report
Bug description:
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.
from collections import UserString
us = UserString("hello world")
sub = UserString("world")
assert us.rfind(sub) == us.rfind(sub.data)
assert us.rindex(sub) == us.rindex(sub.data)Traceback (most recent call last):
File "/src/test.py", line 7, in <module>
assert us.rindex(sub) == us.rindex(sub.data)
^^^^^^^^^^^^^^
File "/py312/lib/python3.12/collections/__init__.py", line 1553, in rindex
return self.data.rindex(sub, start, end)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: must be str, not UserStringCPython versions tested on:
3.12
Operating systems tested on:
Linux
Linked PRs
- gh-140911: Ensure that
UserString.rindex(),UserString.index()accept UserString as sub argument. #140945 - [3.13] gh-140911: Ensure that UserString.index() and UserString.rindex() accept UserString as argument (GH-140945) #141945
- [3.14] gh-140911: Ensure that UserString.index() and UserString.rindex() accept UserString as argument (GH-140945) #141946
Metadata
Metadata
Assignees
Labels
3.13bugs and security fixesbugs and security fixes3.14bugs and security fixesbugs and security fixes3.15new features, bugs and security fixesnew features, bugs and security fixeseasystdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error