`Console.use_theme(theme, inherit=False)` still inherits the current styles
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 1/5
- Tempo stimato
- Meno di un'ora
- Idoneità per principianti
- 88/100
Direzione di ricerca
Il bug si trova in ThemeContext.enter, che chiama self.console.push_theme(self.theme) senza passare il flag inherit memorizzato; la correzione consiste nel passare inherit=self.inherit. Riproduci il problema con lo snippet nella issue, confrontando push_theme(theme, inherit=False) con use_theme(theme, inherit=False), e verifica che repr.number non risulti più evidenziato. Il lavoro è completo quando entrambi gli output coincidono e un test copre use_theme con inherit=False.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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.
- Lingua principale
- Python
- Stelle
- 57.8k
- Fork
- 2.6k
- Merge medio
- 20m
- PR unite (30g)
- 3
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di Textualize/rich
-
Color.parse() raises raw ValueError instead of ColorParseError for an empty rgb(...) componentAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
Textualize/rich#4269 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
Textualize/rich#4268 ·
-
Needs triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
Textualize/rich#4267 ·
-
Difficoltà 1/5 1-3 ore Idoneità per principianti 88/100
Textualize/rich#4266 ·
-
[BUG] `Text.right_crop(0)` empties the text and an amount larger than the text makes `len()` raiseAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
Textualize/rich#4265 ·
Tutte le issue di Textualize/rich
Issue simili
-
author-page correction move-papers
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 78/100
acl-org/acl-anthology#10978 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
GoogleCloudPlatform/professional-services-data-validator#1899 ·
I maintainer di solito rispondono entro 4 giorni
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
HKUDS/CLI-Anything#652 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
Project-N-E-K-O/N.E.K.O#3813 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
Dao-AILab/flash-attention#3191 ·
I maintainer di solito rispondono entro 4 giorni