Skip to content

bpo-39314: Closes parenthesis when autocompleting for functions that take no arguments #20562

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion Lib/rlcompleter.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

import atexit
import builtins
import inspect
import __main__

__all__ = ["Completer"]
Expand Down Expand Up @@ -96,7 +97,13 @@ def complete(self, text, state):

def _callable_postfix(self, val, word):
if callable(val):
word = word + "("
word += "("
try:
if not inspect.signature(val).parameters:
word += ")"
except ValueError:
pass

return word

def global_matches(self, text):
Expand Down
8 changes: 4 additions & 4 deletions Lib/test/test_rlcompleter.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ def test_global_matches(self):

# test with a customized namespace
self.assertEqual(self.completer.global_matches('CompleteM'),
['CompleteMe('])
['CompleteMe()'])
self.assertEqual(self.completer.global_matches('eg'),
['egg('])
# XXX: see issue5256
self.assertEqual(self.completer.global_matches('CompleteM'),
['CompleteMe('])
['CompleteMe()'])

def test_attr_matches(self):
# test with builtins namespace
Expand All @@ -64,7 +64,7 @@ def test_attr_matches(self):
['CompleteMe.spam'])
self.assertEqual(self.completer.attr_matches('Completeme.egg'), [])
self.assertEqual(self.completer.attr_matches('CompleteMe.'),
['CompleteMe.mro(', 'CompleteMe.spam'])
['CompleteMe.mro()', 'CompleteMe.spam'])
self.assertEqual(self.completer.attr_matches('CompleteMe._'),
['CompleteMe._ham'])
matches = self.completer.attr_matches('CompleteMe.__')
Expand Down Expand Up @@ -134,7 +134,7 @@ def test_duplicate_globals(self):
# No opening bracket "(" because we overrode the built-in class
self.assertEqual(completer.complete('memoryview', 0), 'memoryview')
self.assertIsNone(completer.complete('memoryview', 1))
self.assertEqual(completer.complete('Ellipsis', 0), 'Ellipsis(')
self.assertEqual(completer.complete('Ellipsis', 0), 'Ellipsis()')
self.assertIsNone(completer.complete('Ellipsis', 1))

if __name__ == '__main__':
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
:class:`rlcompleter.Completer` and the standard Python shell now close the
parenthesis for functions that take no arguments. Patch contributed by Rémi
Lapeyre.