Method: rich.syntax.ANSISyntaxTheme.get_style_for_token
Calls: 1507, Exceptions: 275, Paths: 5Back
Path 1: 1232 calls (0.82)
_TokenType (1232)
Style (1232)
1def get_style_for_token(self, token_type: TokenType) -> Style:
2 """Look up style in the style map."""
3 try:
4 return self._style_cache[token_type]
5 except KeyError:
6 # Styles form a hierarchy
7 # We need to go from most to least specific
8 # e.g. ("foo", "bar", "baz") to ("foo", "bar") to ("foo",)
9 get_style = self.style_map.get
10 token = tuple(token_type)
11 style = self._missing_style
12 while token:
13 _style = get_style(token)
14 if _style is not None:
15 style = _style
16 break
17 token = token[:-1]
18 self._style_cache[token_type] = style
19 return style
Path 2: 125 calls (0.08)
_TokenType (125)
Style (125)
KeyError (125)
1def get_style_for_token(self, token_type: TokenType) -> Style:
2 """Look up style in the style map."""
3 try:
4 return self._style_cache[token_type]
5 except KeyError:
6 # Styles form a hierarchy
7 # We need to go from most to least specific
8 # e.g. ("foo", "bar", "baz") to ("foo", "bar") to ("foo",)
9 get_style = self.style_map.get
10 token = tuple(token_type)
11 style = self._missing_style
12 while token:
13 _style = get_style(token)
14 if _style is not None:
15 style = _style
16 break
17 token = token[:-1]
18 self._style_cache[token_type] = style
19 return style
Path 3: 72 calls (0.05)
_TokenType (72)
Style (72)
KeyError (72)
1def get_style_for_token(self, token_type: TokenType) -> Style:
2 """Look up style in the style map."""
3 try:
4 return self._style_cache[token_type]
5 except KeyError:
6 # Styles form a hierarchy
7 # We need to go from most to least specific
8 # e.g. ("foo", "bar", "baz") to ("foo", "bar") to ("foo",)
9 get_style = self.style_map.get
10 token = tuple(token_type)
11 style = self._missing_style
12 while token:
13 _style = get_style(token)
14 if _style is not None:
15 style = _style
16 break
17 token = token[:-1]
18 self._style_cache[token_type] = style
19 return style
Path 4: 62 calls (0.04)
_TokenType (61) ('foo', 'bar', 'baz') (1)
Style (62)
KeyError (62)
1def get_style_for_token(self, token_type: TokenType) -> Style:
2 """Look up style in the style map."""
3 try:
4 return self._style_cache[token_type]
5 except KeyError:
6 # Styles form a hierarchy
7 # We need to go from most to least specific
8 # e.g. ("foo", "bar", "baz") to ("foo", "bar") to ("foo",)
9 get_style = self.style_map.get
10 token = tuple(token_type)
11 style = self._missing_style
12 while token:
13 _style = get_style(token)
14 if _style is not None:
15 style = _style
16 break
17 token = token[:-1]
18 self._style_cache[token_type] = style
19 return style
Path 5: 16 calls (0.01)
_TokenType (16)
Style (16)
KeyError (16)
1def get_style_for_token(self, token_type: TokenType) -> Style:
2 """Look up style in the style map."""
3 try:
4 return self._style_cache[token_type]
5 except KeyError:
6 # Styles form a hierarchy
7 # We need to go from most to least specific
8 # e.g. ("foo", "bar", "baz") to ("foo", "bar") to ("foo",)
9 get_style = self.style_map.get
10 token = tuple(token_type)
11 style = self._missing_style
12 while token:
13 _style = get_style(token)
14 if _style is not None:
15 style = _style
16 break
17 token = token[:-1]
18 self._style_cache[token_type] = style
19 return style