Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a7e83b2

Browse files
committed
Fix slowness showing source.
fixes #14831 I was recreating a style for almost every line.
1 parent 6cc4d06 commit a7e83b2

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

IPython/utils/PyColorize.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ def __init__(self, name, base, extra_style, *, symbols={}):
4747
self.base = base
4848
self.extra_style = extra_style
4949
self.symbols = {**_default_symbols, **symbols}
50+
self._formatter = Terminal256Formatter(style=self.as_pygments_style())
5051

5152
@cache
5253
def as_pygments_style(self):
@@ -61,9 +62,8 @@ class MyStyle(Style):
6162
return MyStyle
6263

6364
def format(self, stream: TokenStream) -> str:
64-
style = self.as_pygments_style()
6565

66-
return pygments.format(stream, Terminal256Formatter(style=style))
66+
return pygments.format(stream, self._formatter)
6767

6868
def make_arrow(self, width: int):
6969
"""generate the leading arrow in front of traceback or debugger"""

0 commit comments

Comments
 (0)