FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-133351: Fix Cmd completion for lines beginning with `! ` by godlygeek · Pull Request #133362 · python/cpython · GitHub

/ cpython Public
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (2) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
2 changes: 1 addition & 1 deletion Lib/cmd.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ def complete(self, text, state):
endidx = readline.get_endidx() - stripped
if begidx>0:
cmd, args, foo = self.parseline(line)
if cmd == '':
if cmd in ('', None):
compfunc = self.completedefault
else:
try:
Expand Down
25 changes: 25 additions & 0 deletions Lib/test/test_cmd.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,31 @@ def do_tab_completion_test(self, args):
self.assertIn(b'ab_completion_test', 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 == "! hello":
print('tab completion success')
else:
print('tab completion failure')
return True

simplecmd().cmdloop()
""")

# '! h' and complete 'ello' to '! hello'
input = b"! h\t\n"

output = run_pty(script, input)

self.assertIn(b'ello', output)
self.assertIn(b'tab completion success', output)

def load_tests(loader, tests, pattern):
tests.addTest(doctest.DocTestSuite())
return tests
Expand Down

Back | FazBrowse Home | New Git URL