`Console.use_theme(theme, inherit=False)` still inherits the current styles
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 1/5
- Tiempo estimado
- Menos de una hora
- Aptitud para principiantes
- 88/100
Línea de trabajo
El error está en ThemeContext.enter, que llama a self.console.push_theme(self.theme) sin pasar el indicador inherit almacenado; la corrección consiste en pasar inherit=self.inherit. Reproduce el problema con el fragmento del issue, comparando push_theme(theme, inherit=False) con use_theme(theme, inherit=False), y comprueba que repr.number ya no se resalta. Está listo cuando ambas salidas coinciden y una prueba cubre use_theme con inherit=False.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Hi! I hit this while testing themes. use_theme takes inherit and passes it to ThemeContext, which stores it but then calls self.console.push_theme(self.theme) without it, so the pushed theme always inherits.
import io
from rich.console import Console
from rich.theme import Theme
# A theme that doesn't include the default styles.
theme = Theme({"warning": "red"}, inherit=False)
def render(console):
console.print("[warning]warning[/] 42", end="")
out = console.file.getvalue()
console.file.truncate(0)
console.file.seek(0)
return repr(out)
console = Console(file=io.StringIO(), force_terminal=True, color_system="truecolor")
console.push_theme(theme, inherit=False)
print("push_theme(theme, inherit=False):", render(console))
console.pop_theme()
with console.use_theme(theme, inherit=False):
print("use_theme(theme, inherit=False): ", render(console))
Output on Rich 15.0.0 (and main at 3a109cc):
push_theme(theme, inherit=False): '\x1b[31mwarning\x1b[0m 42'
use_theme(theme, inherit=False): '\x1b[31mwarning\x1b[0m \x1b[1;36m42\x1b[0m'
push_theme drops repr.number, as expected, but use_theme keeps it and the number is still highlighted. I expected both lines to match.
The fix is one line in ThemeContext.__enter__: self.console.push_theme(self.theme, inherit=self.inherit). Happy to open a PR.
Python 3.13, macOS.
- Lenguaje dominante
- Python
- Estrellas
- 57.8k
- Forks
- 2.6k
- Merge medio
- 20 min
- PR fusionados (30 d)
- 3
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/rich
-
Color.parse() raises raw ValueError instead of ColorParseError for an empty rgb(...) componentAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 85/100
Textualize/rich#4269 ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Textualize/rich#4268 ·
-
Needs triage
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Textualize/rich#4267 ·
-
Dificultad 1/5 1-3 horas Aptitud para principiantes 88/100
Textualize/rich#4266 ·
-
[BUG] `Text.right_crop(0)` empties the text and an amount larger than the text makes `len()` raiseAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
Textualize/rich#4265 ·
Todos los issues de Textualize/rich
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