diff --git a/rich/highlighter.py b/rich/highlighter.py index e4c462e2b6..df28048f88 100644 --- a/rich/highlighter.py +++ b/rich/highlighter.py @@ -1,6 +1,6 @@ import re from abc import ABC, abstractmethod -from typing import List, Union +from typing import ClassVar, Sequence, Union from .text import Span, Text @@ -61,8 +61,8 @@ def highlight(self, text: Text) -> None: class RegexHighlighter(Highlighter): """Applies highlighting from a list of regular expressions.""" - highlights: List[str] = [] - base_style: str = "" + highlights: ClassVar[Sequence[str]] = [] + base_style: ClassVar[str] = "" def highlight(self, text: Text) -> None: """Highlight :class:`rich.text.Text` using regular expressions. @@ -81,7 +81,7 @@ class ReprHighlighter(RegexHighlighter): """Highlights the text typically produced from ``__repr__`` methods.""" base_style = "repr." - highlights = [ + highlights: ClassVar[Sequence[str]] = [ r"(?P<)(?P[-\w.:|]*)(?P[\w\W]*)(?P>)", r'(?P[\w_]{1,50})=(?P"?[\w_]+"?)?', r"(?P[][{}()])", @@ -110,8 +110,8 @@ class JSONHighlighter(RegexHighlighter): JSON_STR = r"(?b?\".*?(?[\{\[\(\)\]\}])", r"\b(?Ptrue)\b|\b(?Pfalse)\b|\b(?Pnull)\b", @@ -145,8 +145,8 @@ class ISO8601Highlighter(RegexHighlighter): Regex reference: https://www.oreilly.com/library/view/regular-expressions-cookbook/9781449327453/ch04s07.html """ - base_style = "iso8601." - highlights = [ + base_style: ClassVar[str] = "iso8601." + highlights: ClassVar[Sequence[str]] = [ # # Dates #