diff -r 4252bdba6e89 Lib/rlcompleter.py --- a/Lib/rlcompleter.py Wed Oct 29 10:57:37 2014 +0100 +++ b/Lib/rlcompleter.py Wed Oct 29 13:15:50 2014 +0000 @@ -148,7 +148,8 @@ if word[:n] == attr and hasattr(thisobject, word): val = getattr(thisobject, word) word = self._callable_postfix(val, "%s.%s" % (expr, word)) - matches.append(word) + if word.startswith(text): + matches.append(word) return matches def get_class_members(klass): diff -r 4252bdba6e89 Lib/test/test_rlcompleter.py --- a/Lib/test/test_rlcompleter.py Wed Oct 29 10:57:37 2014 +0100 +++ b/Lib/test/test_rlcompleter.py Wed Oct 29 13:15:50 2014 +0000 @@ -65,6 +67,17 @@ ['egg.{}('.format(x) for x in dir(str) if x.startswith('s')]) + # test that we don't return to many results (issue22141) + class A(object): + def foo(): pass + def foobar(): pass + c = rlcompleter.Completer(locals()) + self.assertEqual(c.complete("A.foo", 0), 'A.foo(') + self.assertEqual(c.complete("A.foo", 1), 'A.foobar(') + self.assertEqual(c.complete("A.foo", 2), None) + self.assertEqual(c.complete("A.foo(", 0), 'A.foo(') + self.assertEqual(c.complete("A.foo(", 1), None) + def test_main(): support.run_unittest(TestRlcompleter)