From e6631fa8fe2c5fccd3fc5d2e742905340cbfa1ae Mon Sep 17 00:00:00 2001 From: Xavier G Date: Fri, 1 Mar 2024 23:21:58 +0100 Subject: [PATCH] Adjust RichLog.highlighter type to allow for custom highlighters. Without an explicit type, tools like mypy assume RichLog.highlighter must be a ReprHighlighter instead of a Highlighter. --- src/textual/widgets/_rich_log.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/textual/widgets/_rich_log.py b/src/textual/widgets/_rich_log.py index 4ba56069a3..404760a96b 100644 --- a/src/textual/widgets/_rich_log.py +++ b/src/textual/widgets/_rich_log.py @@ -5,7 +5,7 @@ from typing import TYPE_CHECKING, Optional, cast from rich.console import RenderableType -from rich.highlighter import ReprHighlighter +from rich.highlighter import Highlighter, ReprHighlighter from rich.measure import measure_renderables from rich.pretty import Pretty from rich.protocol import is_renderable @@ -86,7 +86,8 @@ def __init__( """Apply Rich console markup.""" self.auto_scroll = auto_scroll """Automatically scroll to the end on write.""" - self.highlighter = ReprHighlighter() + self.highlighter: Highlighter = ReprHighlighter() + """Rich Highlighter used to highlight content when highlight is True""" self._last_container_width: int = min_width """Record the last width we rendered content at."""