Skip to content

Commit 90520a8

Browse files
committed
monkeypatch rlcompleter's _callable_postfix to prevent side-effects (__getattr__/__getattribute__)
1 parent e7a5c34 commit 90520a8

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

bpython/cli.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,10 @@ def __init__(self, scr, interp, statusbar=None, idle=None):
301301
# Use the interpreter's namespace only for the readline stuff:
302302
self.completer = rlcompleter.Completer(self.interp.locals)
303303
self.completer.attr_matches = self.attr_matches
304+
# Gna, Py 2.6's rlcompleter searches for __call__ inside the
305+
# instance instead of the type, so we monkeypatch to prevent
306+
# side-effects (__getattr__/__getattribute__)
307+
self.completer._callable_postfix = self._callable_postfix
304308
self.statusbar = statusbar
305309
self.list_win = curses.newwin(1, 1, 1, 1)
306310
self.idle = idle
@@ -396,6 +400,12 @@ def attr_lookup(self, obj, expr, attr):
396400
matches.append("%s.%s" % (expr, word))
397401
return matches
398402

403+
def _callable_postfix(self, value, word):
404+
"""rlcompleter's _callable_postfix done right."""
405+
if hasattr(type(value), '__call__'):
406+
word += '('
407+
return word
408+
399409
def cw(self):
400410
"""Return the current word, i.e. the (incomplete) word directly to the
401411
left of the cursor"""

0 commit comments

Comments
 (0)