Skip to content

Commit 128e4b5

Browse files
committed
Compile regex
Signed-off-by: Sebastian Ramacher <sebastian+dev@ramacher.at>
1 parent 43c43de commit 128e4b5

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

bpython/repl.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
from .config import getpreferredencoding
5353
from .formatter import Parenthesis
5454
from .history import History
55+
from .lazyre import LazyReCompile
5556
from .paste import PasteHelper, PastePinnwand, PasteFailed
5657
from .patch_linecache import filename_for_console_input
5758
from .translations import _, ngettext
@@ -83,6 +84,8 @@ def estimate(self):
8384
class 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

Comments
 (0)