collections.UserString.startswith() and endswith() reject UserString arguments
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 78/100
Línea de trabajo
Lee Lib/collections/__init__.py y los métodos existentes de UserString que desenvuelven .data, y luego examina el cambio relacionado en issue #140911 y PR #140945. Añade pruebas específicas para startswith() y endswith() con argumentos UserString, incluido el caso de reproducción reportado; el trabajo está terminado cuando ambos devuelvan True y el comportamiento de str ordinario no cambie.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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
- Lenguaje dominante
- Python
- Estrellas
- 77.6k
- Forks
- 38.4k
- Merge medio
- 20 h 19 min
- PR fusionados (30 d)
- 624
Preparar el entorno
Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de python/cpython
-
Remove unused FVS_* macrosAbiertointerpreter-core type-feature
Dificultad 1/5 Menos de una hora Aptitud para principiantes 78/100
Los mantenedores suelen responder en 1 día
-
extension-modules type-bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
python/cpython#160001 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
stdlib topic-XML type-bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
Los mantenedores suelen responder en 1 día
-
Docs: problem with page "msvcrt — Useful routines from the MS VC runtime"Quizá libre de nuevo @jikekei la tomó hace 11 días y no hay ningún pull request abierto. Abiertodocs
Dificultad 1/5 Menos de una hora Aptitud para principiantes 85/100
python/cpython#159072 · 6 comentarios ·
Los mantenedores suelen responder en 1 día
-
Document unpacking in generator expressions (PEP 798)Posiblemente ocupada @Marwan-verse la tomó hace 9 días. Abiertodocs
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
python/cpython#159061 · 1 comentario ·
Los mantenedores suelen responder en 1 día
Todos los issues de python/cpython
Issues similares
-
infrastructure
Dificultad 2/5 1-3 horas Aptitud para principiantes 74/100
khuisman/mcp-gee-sweet#1152 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
-
backroom bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
ditto-assistant/ditto-subnet#3069 ·
Los mantenedores suelen responder en 1 día
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 67/100
open-webui/open-webui#32901 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
0.3.3 bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Los mantenedores suelen responder en 1 día