world
hello
startswith TypeError startswith first arg must be str or a tuple of str, not UserString
endswith TypeError endswith first arg must be str or a tuple of str, not UserString
Expected behavior
Both prefix/suffix checks return True, consistently with the related UserString methods accepting UserString arguments.
Implementation details
In Lib/collections/__init__.py, UserString.startswith() and endswith() delegate directly to the underlying str without unwrapping the argument’s .data. Related methods explicitly unwrap UserString arguments.
Issue #140911 and PR #140945 fixed a similar inconsistency in UserString.index() and rindex().
This report concerns accepting UserString arguments in UserString methods, not changing str.startswith() or str.endswith() or introducing arbitrary string coercion.
Activity
gh-159868: Accept UserString arguments in startswith and endswith (#1…