diff --git a/Lib/rlcompleter.py b/Lib/rlcompleter.py index 94f9341beef..d517c0e2d39 100644 --- a/Lib/rlcompleter.py +++ b/Lib/rlcompleter.py @@ -73,6 +73,12 @@ class Completer: if self.use_main_ns: self.namespace = __main__.__dict__ + if not text.strip(): + if state == 0: + return '\t' + else: + return None + if state == 0: if "." in text: self.matches = self.attr_matches(text) diff --git a/Lib/test/test_rlcompleter.py b/Lib/test/test_rlcompleter.py index 9d4d0bdeaf2..d37b620b7a4 100644 --- a/Lib/test/test_rlcompleter.py +++ b/Lib/test/test_rlcompleter.py @@ -64,5 +64,13 @@ class TestRlcompleter(unittest.TestCase): ['egg.{}('.format(x) for x in dir(str) if x.startswith('s')]) + def test_complete(self): + completer = rlcompleter.Completer() + self.assertEqual(completer.complete('', 0), '\t') + self.assertEqual(completer.complete('a', 0), 'and') + self.assertEqual(completer.complete('a', 1), 'as') + self.assertEqual(completer.complete('as', 2), 'assert') + self.assertEqual(completer.complete('an', 0), 'and') + if __name__ == '__main__': unittest.main() diff --git a/Misc/NEWS b/Misc/NEWS index 1e1a88c466a..22323577c53 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -62,6 +62,9 @@ Core and Builtins Library ------- +- Issue #23441: rcompleter now prints a tab character instead of displaying + possible completions for an empty word. Initial patch by Martin Sekera. + - Issue #24683: Fixed crashes in _json functions called with arguments of inappropriate type.