]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-39314: Closes parenthesis when autocompleting for functions that take no argument...
authorRémi Lapeyre <remi.lapeyre@lenstra.fr>
Tue, 30 Jun 2020 13:48:15 +0000 (15:48 +0200)
committerGitHub <noreply@github.com>
Tue, 30 Jun 2020 13:48:15 +0000 (22:48 +0900)
Lib/rlcompleter.py
Lib/test/test_rlcompleter.py
Misc/NEWS.d/next/Library/2020-06-01-02-16-29.bpo-39314.0T9hlA.rst [new file with mode: 0644]

index bca4a7bc5218a90d7ad145ae1d57e9eb489daeda..c06388e8d9c2dd8d5f2c113f838234f9620c3aeb 100644 (file)
@@ -31,6 +31,7 @@ Notes:
 
 import atexit
 import builtins
+import inspect
 import __main__
 
 __all__ = ["Completer"]
@@ -96,7 +97,13 @@ class Completer:
 
     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):
index 0dc1080ca32093cf0e82455ec81cebbed72a9566..ee3019d8782d17f88f0b3cbfa91d5a3a4880e3b7 100644 (file)
@@ -40,12 +40,12 @@ class TestRlcompleter(unittest.TestCase):
 
         # 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
@@ -64,7 +64,7 @@ class TestRlcompleter(unittest.TestCase):
                          ['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.__')
@@ -134,7 +134,7 @@ class TestRlcompleter(unittest.TestCase):
         # 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__':
diff --git a/Misc/NEWS.d/next/Library/2020-06-01-02-16-29.bpo-39314.0T9hlA.rst b/Misc/NEWS.d/next/Library/2020-06-01-02-16-29.bpo-39314.0T9hlA.rst
new file mode 100644 (file)
index 0000000..e805332
--- /dev/null
@@ -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.