Skip to content

Commit fa4c2d5

Browse files
authored
Merge pull request #3939 from Textualize/highlights-typing
typing highlighter
2 parents 3286095 + 624b30c commit fa4c2d5

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

rich/highlighter.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import re
22
from abc import ABC, abstractmethod
3-
from typing import List, Union
3+
from typing import ClassVar, Sequence, Union
44

55
from .text import Span, Text
66

@@ -61,8 +61,8 @@ def highlight(self, text: Text) -> None:
6161
class RegexHighlighter(Highlighter):
6262
"""Applies highlighting from a list of regular expressions."""
6363

64-
highlights: List[str] = []
65-
base_style: str = ""
64+
highlights: ClassVar[Sequence[str]] = []
65+
base_style: ClassVar[str] = ""
6666

6767
def highlight(self, text: Text) -> None:
6868
"""Highlight :class:`rich.text.Text` using regular expressions.
@@ -81,7 +81,7 @@ class ReprHighlighter(RegexHighlighter):
8181
"""Highlights the text typically produced from ``__repr__`` methods."""
8282

8383
base_style = "repr."
84-
highlights = [
84+
highlights: ClassVar[Sequence[str]] = [
8585
r"(?P<tag_start><)(?P<tag_name>[-\w.:|]*)(?P<tag_contents>[\w\W]*)(?P<tag_end>>)",
8686
r'(?P<attrib_name>[\w_]{1,50})=(?P<attrib_value>"?[\w_]+"?)?',
8787
r"(?P<brace>[][{}()])",
@@ -110,8 +110,8 @@ class JSONHighlighter(RegexHighlighter):
110110
JSON_STR = r"(?<![\\\w])(?P<str>b?\".*?(?<!\\)\")"
111111
JSON_WHITESPACE = {" ", "\n", "\r", "\t"}
112112

113-
base_style = "json."
114-
highlights = [
113+
base_style: ClassVar[str] = "json."
114+
highlights: ClassVar[Sequence[str]] = [
115115
_combine_regex(
116116
r"(?P<brace>[\{\[\(\)\]\}])",
117117
r"\b(?P<bool_true>true)\b|\b(?P<bool_false>false)\b|\b(?P<null>null)\b",
@@ -145,8 +145,8 @@ class ISO8601Highlighter(RegexHighlighter):
145145
Regex reference: https://www.oreilly.com/library/view/regular-expressions-cookbook/9781449327453/ch04s07.html
146146
"""
147147

148-
base_style = "iso8601."
149-
highlights = [
148+
base_style: ClassVar[str] = "iso8601."
149+
highlights: ClassVar[Sequence[str]] = [
150150
#
151151
# Dates
152152
#

0 commit comments

Comments
 (0)