From 627a666db05a0a70ac54fe6456719ee0530b5df7 Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Sun, 11 May 2008 21:03:42 +0000 Subject: [PATCH] - #2250: Exceptions raised during evaluation of names in rlcompleter's ``Completer.complete()`` method are now caught and ignored. --- Doc/library/rlcompleter.rst | 3 ++- Lib/rlcompleter.py | 5 ++++- Misc/NEWS | 3 +++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/Doc/library/rlcompleter.rst b/Doc/library/rlcompleter.rst index b882cb0e9b..6816d39104 100644 --- a/Doc/library/rlcompleter.rst +++ b/Doc/library/rlcompleter.rst @@ -61,5 +61,6 @@ Completer objects have the following method: If called for a dotted name, it will try to evaluate anything without obvious side-effects (functions will not be evaluated, but it can generate calls to :meth:`__getattr__`) up to the last part, and find matches for the rest via the - :func:`dir` function. + :func:`dir` function. Any exception raised during the evaluation of the + expression is caught, silenced and :const:`None` is returned. diff --git a/Lib/rlcompleter.py b/Lib/rlcompleter.py index a2d5fe6a8f..36965e6eec 100644 --- a/Lib/rlcompleter.py +++ b/Lib/rlcompleter.py @@ -127,7 +127,10 @@ class Completer: if not m: return [] expr, attr = m.group(1, 3) - object = eval(expr, self.namespace) + try: + object = eval(expr, self.namespace) + except Exception: + return [] words = dir(object) if hasattr(object,'__class__'): words.append('__class__') diff --git a/Misc/NEWS b/Misc/NEWS index 4fd972a1fa..f843f2a160 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -23,6 +23,9 @@ Extension Modules Library ------- +- #2250: Exceptions raised during evaluation of names in rlcompleter's + ``Completer.complete()`` method are now caught and ignored. + - #2659: Added ``break_on_hyphens`` option to textwrap TextWrapper class. - The mhlib module has been deprecated for removal in Python 3.0. -- 2.50.0