Skip to content

collections.UserString.rindex() fails to accept UserString as sub argument#140911

@T90REAL

Description

@T90REAL

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.

fromcollectionsimportUserStringus=UserString("hello world") sub=UserString("world") assertus.rfind(sub) ==us.rfind(sub.data) assertus.rindex(sub) ==us.rindex(sub.data)
Traceback (mostrecentcalllast): File"/src/test.py", line7, in<module>assertus.rindex(sub) ==us.rindex(sub.data) ^^^^^^^^^^^^^^File"/py312/lib/python3.12/collections/__init__.py", line1553, inrindexreturnself.data.rindex(sub, start, end) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^TypeError: mustbestr, notUserString

CPython versions tested on:

3.12

Operating systems tested on:

Linux

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.13bugs and security fixes3.14bugs and security fixes3.15new features, bugs and security fixeseasystdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions