`ListView.remove_items()` doesn't adjust the highlighted index when `indices` is a generator
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 50/100
Línea de trabajo
The bug is in ListView.remove_items(), which iterates the indices argument twice: once to pick the items to remove and again to build normalized_indices used to adjust the highlighted index. Run the reproduction script with a list and with a generator to confirm the mismatch. Done means both inputs leave index and highlighted_child identical. The reporter says a PR with a test exists but is not linked, so check the thread before starting.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Hi! I hit this while writing generated tests against Textual's widgets.
remove_items(indices: Iterable[int]) iterates indices twice: once to find the items to remove, and again to build normalized_indices. With a generator the second pass is empty, so the index isn't adjusted for the removed items.
import asyncio
import textual
from textual.app import App, ComposeResult
from textual.widgets import Label, ListItem, ListView
class ListApp(App):
def compose(self) -> ComposeResult:
yield ListView(*[ListItem(Label(f"item {n}"), id=f"item{n}") for n in range(5)])
async def run(label: str, make_indices) -> None:
app = ListApp()
async with app.run_test() as pilot:
list_view = app.query_one(ListView)
list_view.index = 3
await pilot.pause()
await list_view.remove_items(make_indices())
await pilot.pause()
highlighted = list_view.highlighted_child
print(
f"{label:>9}: index={list_view.index}",
f"highlighted={highlighted.id if highlighted else None}",
)
async def main() -> None:
print("highlight item3, then remove items 0 and 1")
await run("list", lambda: [0, 1])
await run("generator", lambda: (n for n in [0, 1]))
print("Textual", textual.__version__)
asyncio.run(main())
Output on Textual 8.2.7 (and the same on main at 5e5b7ef):
highlight item3, then remove items 0 and 1
list: index=1 highlighted=item3
generator: index=3 highlighted=None
With a generator, index stays at 3, which is now past the end of the three remaining items, so nothing is highlighted. I expected the same result as with a list. Turning indices into a list at the top of the method fixes it; I have a PR with a test ready.
- Lenguaje dominante
- Python
- Estrellas
- 37.7k
- Forks
- 1.5k
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Preparar el entorno
- 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 Textualize/textual
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Textualize/textual#6790 · 2 comentarios ·
-
Markdown table of contents: the node added for a skipped heading level shows the wrong numeralAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 80/100
Textualize/textual#6789 · 1 comentario ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Textualize/textual#6787 · 1 comentario ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Textualize/textual#6782 · 1 comentario ·
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 85/100
Textualize/textual#6778 · 1 comentario ·
Todos los issues de Textualize/textual
Issues similares
-
Internal ErrorAbiertobug
Dificultad 2/5 1-3 horas Aptitud para principiantes 66/100
frappe/frappe_docker#2071 ·
Los mantenedores suelen responder en 1 día
-
bug python
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
traceloop/openllmetry#4717 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
The-Pocket/PocketFlow#161 ·
-
[Bug]: Webapp workspace fails to render in Safari — "Can't find variable: requestIdleCallback"Abiertocomp/desktop P2 type/bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
NousResearch/hermes-agent#157702 ·
Los mantenedores suelen responder en 1 día
-
scibench_physics / scibench_chemistry: a correct answer scores 0 when the unit has a power of tenPosiblemente ocupada @BahaaMattar la tomó hoy. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
EvolvingLMMs-Lab/lmms-eval#1699 ·
Los mantenedores suelen responder en 1 día