Skip to content

bpo-35270: Cmd.complete: use completedefault also with cmd=None #10588

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion Lib/cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ def complete(self, text, state):
endidx = readline.get_endidx() - stripped
if begidx>0:
cmd, args, foo = self.parseline(line)
if cmd == '':
if not cmd:
compfunc = self.completedefault
else:
try:
Expand Down
17 changes: 17 additions & 0 deletions Lib/test/test_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import io
import textwrap
from test import support
from unittest.mock import patch
from test.support.import_helper import import_module
from test.support.pty_helper import run_pty

Expand Down Expand Up @@ -246,6 +247,22 @@ def test_input_reset_at_EOF(self):
"(Cmd) \n"
"(Cmd) *** Unknown syntax: EOF\n"))

def test_complete_with_None_from_parseline(self, *args):
readline = import_module('readline')

with (patch('readline.get_line_buffer', return_value='foo'),
patch('readline.get_begidx', return_value=2),
patch('readline.get_endidx', return_value=2)):
class CustomCmd(cmd.Cmd):
def parseline(self, line):
return None, None, line

def completedefault(self, *args):
return ['via_completedefault']

c = CustomCmd()
self.assertEqual(c.complete("", 0), "via_completedefault")


class CmdPrintExceptionClass(cmd.Cmd):
"""
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Cmd.complete: use ``completedefault`` also with ``cmd=None`` returned from ``parseline``. Patch contributed by Daniel Hahler.