collections.UserString.startswith() and endswith() reject UserString arguments
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
調査の方向性
Lib/collections/__init__.pyと、.dataを取り出す既存のUserStringメソッドを読み、その後、issue #140911とPR #140945の関連する変更を確認してください。UserString引数を使ったstartswith()とendswith()の焦点を絞ったテストを追加し、報告された再現ケースも含めてください。両方がTrueを返し、通常のstrの動作が変わらないことをもって完了とします。
索引モデルが issue の本文から書いたものです。
説明
Bug report
Bug description
collections.UserString.startswith() and endswith() raise TypeError when their prefix or suffix is another UserString.
This is inconsistent with UserString.removeprefix(), removesuffix(), find(), and index(), which accept UserString arguments.
Reproducer
from collections import UserString
text = UserString("hello world")
print(text.removeprefix(UserString("hello")))
print(text.removesuffix(UserString("world")))
for method, argument in (
("startswith", UserString("hello")),
("endswith", UserString("world")),
):
try:
print(method, getattr(text, method)(argument))
except TypeError as exc:
print(method, type(exc).__name__, exc)
Actual output
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.
CPython versions tested on:
3.14
Operating systems tested on:
macOS
Linked PRs
- gh-159869
- 主要言語
- Python
- スター
- 77.6k
- フォーク
- 38.4k
- 平均マージ
- 20時間 19分
- マージ済み PR(30日)
- 624
環境構築
このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
python/cpython のほかの issue
-
interpreter-core type-feature
難易度 1/5 1時間未満 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
extension-modules type-bug
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
python/cpython#160001 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
stdlib topic-XML type-bug
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
メンテナーはふだん 1 日以内に返信
-
Docs: problem with page "msvcrt — Useful routines from the MS VC runtime"再び着手できるかも @jikekei が 11 日前に担当しましたが、オープン中のプルリクエストはありません。 オープンdocs
難易度 1/5 1時間未満 初心者へのやさしさ 85/100
python/cpython#159072 · コメント 6 件 ·
メンテナーはふだん 1 日以内に返信
-
Document unpacking in generator expressions (PEP 798)対応中かも @Marwan-verse が 9 日前に担当しました。 オープンdocs
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
python/cpython#159061 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
似ている issue
-
infrastructure
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
khuisman/mcp-gee-sweet#1152 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
-
backroom bug
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
ditto-assistant/ditto-subnet#3069 ·
メンテナーはふだん 1 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 67/100
open-webui/open-webui#32901 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
0.3.3 bug
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信