From 907316f18d17f054762448e84e5eb87f29129ac3 Mon Sep 17 00:00:00 2001 From: Thomas Kluyver Date: Mon, 14 Aug 2017 15:53:07 +0100 Subject: [PATCH 1/2] Limit number of completions returned --- IPython/core/completer.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/IPython/core/completer.py b/IPython/core/completer.py index 029cfe13bdf..bb5649cf5ca 100644 --- a/IPython/core/completer.py +++ b/IPython/core/completer.py @@ -161,6 +161,9 @@ else: PROTECTABLES = ' ()[]{}?=\\|;:\'#*"^&' +# Protect against returning an enormous number of completions which the frontend +# may have trouble processing. +MATCHES_LIMIT = 500 _deprecation_readline_sentinel = object() @@ -1944,7 +1947,8 @@ def _complete(self, *, cursor_line, cursor_pos, line_buffer=None, text=None, for meth in (self.unicode_name_matches, back_latex_name_matches, back_unicode_name_matches): name_text, name_matches = meth(base_text) if name_text: - return name_text, name_matches, [meth.__qualname__]*len(name_matches), () + return name_text, name_matches[:MATCHES_LIMIT], \ + [meth.__qualname__]*min(len(name_matches), MATCHES_LIMIT), () # If no line buffer is given, assume the input text is all there was @@ -1956,11 +1960,10 @@ def _complete(self, *, cursor_line, cursor_pos, line_buffer=None, text=None, # Do magic arg matches for matcher in self.magic_arg_matchers: - matches = [(m, matcher.__qualname__) for m in matcher(line_buffer)] + matches = list(matcher(line_buffer))[:MATCHES_LIMIT] if matches: - matches2 = [m[0] for m in matches] - origins = [m[1] for m in matches] - return text, matches2, origins, () + origins = [matcher.__qualname__] * len(matches) + return text, matches, origins, () # Start with a clean slate of completions matches = [] @@ -2007,7 +2010,8 @@ def _complete(self, *, cursor_line, cursor_pos, line_buffer=None, text=None, seen.add(t) _filtered_matches = sorted( - set(filtered_matches), key=lambda x: completions_sorting_key(x[0])) + set(filtered_matches), key=lambda x: completions_sorting_key(x[0]))\ + [:MATCHES_LIMIT] _matches = [m[0] for m in _filtered_matches] origins = [m[1] for m in _filtered_matches] From ed0c88f891806cef77b7b79dd2a8007c7aa1b796 Mon Sep 17 00:00:00 2001 From: Thomas Kluyver Date: Mon, 14 Aug 2017 15:54:08 +0100 Subject: [PATCH 2/2] Ignore generated shortcut lists --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index c10cded6d18..1a673093556 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ _build docs/man/*.gz docs/source/api/generated docs/source/config/options +docs/source/config/shortcuts/*.csv docs/source/interactive/magics-generated.txt docs/gh-pages jupyter_notebook/notebook/static/mathjax