Skip to content

Commit

Permalink
Silence errors from custom attribute completer functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
takluyver committed Oct 20, 2011
1 parent b59cc86 commit 2e01c88
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
4 changes: 4 additions & 0 deletions IPython/core/completer.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,10 @@ def attr_matches(self, text):
words = generics.complete_object(obj, words)
except TryNext:
pass
except Exception:
# Silence errors from completion function
#raise # dbg
pass
# Build match list to return
n = len(attr)
res = ["%s.%s" % (expr, w) for w in words if w[:n] == attr ]
Expand Down
13 changes: 13 additions & 0 deletions IPython/core/tests/test_completer.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from IPython.core import completer
from IPython.external.decorators import knownfailureif
from IPython.utils.tempdir import TemporaryDirectory
from IPython.utils.generics import complete_object

#-----------------------------------------------------------------------------
# Test functions
Expand Down Expand Up @@ -83,6 +84,18 @@ def test_line_split():
# all inputs turned into unicode
check_line_split(sp, [ map(unicode, p) for p in t] )

def test_custom_completion_error():
"""Test that errors from custom attribute completers are silenced."""
ip = get_ipython()
class A(object): pass
ip.user_ns['a'] = A()

@complete_object.when_type(A)
def complete_A(a, existing_completions):
raise TypeError("this should be silenced")

ip.complete("a.")


def test_unicode_completions():
ip = get_ipython()
Expand Down

0 comments on commit 2e01c88

Please sign in to comment.