Skip to content

Commit 3ab27eb

Browse files
committed
Lazy compilation of regex
Signed-off-by: Sebastian Ramacher <sebastian+dev@ramacher.at>
1 parent 80e7706 commit 3ab27eb

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

bpython/autocomplete.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,12 +455,17 @@ def safe_eval(expr, namespace):
455455
raise EvaluationError
456456

457457

458-
attr_matches_re = re.compile(r"(\w+(\.\w+)*)\.(\w*)")
458+
attr_matches_re = None
459+
459460

460461
def attr_matches(text, namespace):
461462
"""Taken from rlcompleter.py and bent to my will.
462463
"""
463464

465+
global attr_matches_re
466+
if attr_matches_re is None:
467+
attr_matches_re = re.compile(r"(\w+(\.\w+)*)\.(\w*)")
468+
464469
# Gna, Py 2.6's rlcompleter searches for __call__ inside the
465470
# instance instead of the type, so we monkeypatch to prevent
466471
# side-effects (__getattr__/__getattribute__)

0 commit comments

Comments
 (0)