[Python-checkins] (no subject)

Rémi Lapeyre webhook-mailer at python.org
Tue Jun 30 09:48:20 EDT 2020


To: python-checkins at python.org
Subject: bpo-39314: Closes parenthesis when autocompleting for functions that
 take no arguments (GH-20562)
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: quoted-printable
MIME-Version: 1.0
https://github.com/python/cpython/commit/bd4a3f21454a6012f4353e2255837561fc9f=
0e6a
commit: bd4a3f21454a6012f4353e2255837561fc9f0e6a
branch: master
author: R=C3=A9mi Lapeyre <remi.lapeyre at lenstra.fr>
committer: GitHub <noreply at github.com>
date: 2020年06月30日T22:48:15+09:00
summary:
bpo-39314: Closes parenthesis when autocompleting for functions that take no =
arguments (GH-20562)
files:
A Misc/NEWS.d/next/Library/2020-06-01-02-16-29.bpo-39314.0T9hlA.rst
M Lib/rlcompleter.py
M Lib/test/test_rlcompleter.py
diff --git a/Lib/rlcompleter.py b/Lib/rlcompleter.py
index bca4a7bc5218a..c06388e8d9c2d 100644
--- a/Lib/rlcompleter.py
+++ b/Lib/rlcompleter.py
@@ -31,6 +31,7 @@
=20
 import atexit
 import builtins
+import inspect
 import __main__
=20
 __all__ =3D ["Completer"]
@@ -96,7 +97,13 @@ def complete(self, text, state):
=20
 def _callable_postfix(self, val, word):
 if callable(val):
- word =3D word + "("
+ word +=3D "("
+ try:
+ if not inspect.signature(val).parameters:
+ word +=3D ")"
+ except ValueError:
+ pass
+
 return word
=20
 def global_matches(self, text):
diff --git a/Lib/test/test_rlcompleter.py b/Lib/test/test_rlcompleter.py
index 0dc1080ca3209..ee3019d8782d1 100644
--- a/Lib/test/test_rlcompleter.py
+++ b/Lib/test/test_rlcompleter.py
@@ -40,12 +40,12 @@ def test_global_matches(self):
=20
 # 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()'])
=20
 def test_attr_matches(self):
 # test with builtins namespace
@@ -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 =3D self.completer.attr_matches('CompleteMe.__')
@@ -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))
=20
 if __name__ =3D=3D '__main__':
diff --git a/Misc/NEWS.d/next/Library/2020-06-01-02-16-29.bpo-39314.0T9hlA.rs=
t b/Misc/NEWS.d/next/Library/2020-06-01-02-16-29.bpo-39314.0T9hlA.rst
new file mode 100644
index 0000000000000..e805332efb626
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2020-06-01-02-16-29.bpo-39314.0T9hlA.rst
@@ -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=C3=
=A9mi
+Lapeyre.


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /