5252from .config import getpreferredencoding
5353from .formatter import Parenthesis
5454from .history import History
55+ from .lazyre import LazyReCompile
5556from .paste import PasteHelper , PastePinnwand , PasteFailed
5657from .patch_linecache import filename_for_console_input
5758from .translations import _ , ngettext
@@ -83,6 +84,8 @@ def estimate(self):
8384class Interpreter (code .InteractiveInterpreter ):
8485 """Source code interpreter for use in bpython."""
8586
87+ bpython_input_re = LazyReCompile (r'<bpython-input-\d+>' )
88+
8689 def __init__ (self , locals = None , encoding = None ):
8790 """Constructor.
8891
@@ -197,7 +200,7 @@ def showsyntaxerror(self, filename=None):
197200 else :
198201 # Stuff in the right filename and right lineno
199202 # strip linecache line number
200- if re . match (r'<bpython-input-\d+>' , filename ):
203+ if self . bpython_input_re . match (filename ):
201204 filename = '<input>'
202205 if filename == '<input>' and not py3 :
203206 lineno -= 2
@@ -220,7 +223,7 @@ def showtraceback(self):
220223
221224 for i , (fname , lineno , module , something ) in enumerate (tblist ):
222225 # strip linecache line number
223- if re . match (r'<bpython-input-\d+>' , fname ):
226+ if self . bpython_input_re . match (fname ):
224227 fname = '<input>'
225228 tblist [i ] = (fname , lineno , module , something )
226229 # Set the right lineno (encoding header adds an extra line)
0 commit comments