Method: rich.syntax.PygmentsSyntaxTheme.get_style_for_token
Calls: 858, Exceptions: 113, Paths: 3Back
Path 1: 745 calls (0.87)
_TokenType (745)
Style (745)
1def get_style_for_token(self, token_type: TokenType) -> Style:
2 """Get a style from a Pygments class."""
3 try:
4 return self._style_cache[token_type]
5 except KeyError:
6 try:
7 pygments_style = self._pygments_style_class.style_for_token(token_type)
8 except KeyError:
9 style = Style.null()
10 else:
11 color = pygments_style["color"]
12 bgcolor = pygments_style["bgcolor"]
13 style = Style(
14 color="#" + color if color else "#000000",
15 bgcolor="#" + bgcolor if bgcolor else self._background_color,
16 bold=pygments_style["bold"],
17 italic=pygments_style["italic"],
18 underline=pygments_style["underline"],
19 )
20 self._style_cache[token_type] = style
21 return style
Path 2: 112 calls (0.13)
_TokenType (112)
Style (112)
KeyError (112)
1def get_style_for_token(self, token_type: TokenType) -> Style:
2 """Get a style from a Pygments class."""
3 try:
4 return self._style_cache[token_type]
5 except KeyError:
6 try:
7 pygments_style = self._pygments_style_class.style_for_token(token_type)
8 except KeyError:
9 style = Style.null()
10 else:
11 color = pygments_style["color"]
12 bgcolor = pygments_style["bgcolor"]
13 style = Style(
14 color="#" + color if color else "#000000",
15 bgcolor="#" + bgcolor if bgcolor else self._background_color,
16 bold=pygments_style["bold"],
17 italic=pygments_style["italic"],
18 underline=pygments_style["underline"],
19 )
20 self._style_cache[token_type] = style
21 return style
Path 3: 1 calls (0.0)
'abc' (1)
Style (1)
KeyError (1)
1def get_style_for_token(self, token_type: TokenType) -> Style:
2 """Get a style from a Pygments class."""
3 try:
4 return self._style_cache[token_type]
5 except KeyError:
6 try:
7 pygments_style = self._pygments_style_class.style_for_token(token_type)
8 except KeyError:
9 style = Style.null()
10 else:
11 color = pygments_style["color"]
12 bgcolor = pygments_style["bgcolor"]
13 style = Style(
14 color="#" + color if color else "#000000",
15 bgcolor="#" + bgcolor if bgcolor else self._background_color,
16 bold=pygments_style["bold"],
17 italic=pygments_style["italic"],
18 underline=pygments_style["underline"],
19 )
20 self._style_cache[token_type] = style
21 return style