mirror of
https://github.com/python/cpython.git
synced 2025-07-07 19:35:27 +00:00
gh-133363: Fix Cmd completion for lines beginning with !
(#133364)
This commit is contained in:
parent
3b4333583f
commit
1d9406e426
3 changed files with 28 additions and 1 deletions
|
@ -273,7 +273,7 @@ class Cmd:
|
||||||
endidx = readline.get_endidx() - stripped
|
endidx = readline.get_endidx() - stripped
|
||||||
if begidx>0:
|
if begidx>0:
|
||||||
cmd, args, foo = self.parseline(line)
|
cmd, args, foo = self.parseline(line)
|
||||||
if cmd == '':
|
if not cmd:
|
||||||
compfunc = self.completedefault
|
compfunc = self.completedefault
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -289,6 +289,30 @@ class CmdTestReadline(unittest.TestCase):
|
||||||
self.assertIn(b'ab_completion_test', output)
|
self.assertIn(b'ab_completion_test', output)
|
||||||
self.assertIn(b'tab completion success', output)
|
self.assertIn(b'tab completion success', output)
|
||||||
|
|
||||||
|
def test_bang_completion_without_do_shell(self):
|
||||||
|
script = textwrap.dedent("""
|
||||||
|
import cmd
|
||||||
|
class simplecmd(cmd.Cmd):
|
||||||
|
def completedefault(self, text, line, begidx, endidx):
|
||||||
|
return ["hello"]
|
||||||
|
|
||||||
|
def default(self, line):
|
||||||
|
if line.replace(" ", "") == "!hello":
|
||||||
|
print('tab completion success')
|
||||||
|
else:
|
||||||
|
print('tab completion failure')
|
||||||
|
return True
|
||||||
|
|
||||||
|
simplecmd().cmdloop()
|
||||||
|
""")
|
||||||
|
|
||||||
|
# '! h' or '!h' and complete 'ello' to 'hello'
|
||||||
|
for input in [b"! h\t\n", b"!h\t\n"]:
|
||||||
|
with self.subTest(input=input):
|
||||||
|
output = run_pty(script, input)
|
||||||
|
self.assertIn(b'hello', output)
|
||||||
|
self.assertIn(b'tab completion success', output)
|
||||||
|
|
||||||
def load_tests(loader, tests, pattern):
|
def load_tests(loader, tests, pattern):
|
||||||
tests.addTest(doctest.DocTestSuite())
|
tests.addTest(doctest.DocTestSuite())
|
||||||
return tests
|
return tests
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
The :class:`cmd.Cmd` class has been fixed to reliably call the ``completedefault``
|
||||||
|
method whenever the ``do_shell`` method is not defined and tab completion is
|
||||||
|
requested for a line beginning with ``!``.
|
Loading…
Add table
Add a link
Reference in a new issue