Search code examples
pythonpython-3.xread-eval-print-loop

Setting completekey=None removes up-arrow functionality


I'm trying to write a small REPL using the cmd library in Python. One of the features that it provides is automatic tab completion, which I do not want.

Luckily, the docs mention "If completekey is not None and readline is available, command completion is done automatically." So I set completekey=None when I instantiated my cmd.Cmd subclass, which worked.

However, the main functionality of the cmd module, the use of readline which gives support for up-arrow history, was also disabled, and now I'm back to ^[[A's.

Why is this happening, and is there a solution?


Solution

  • The readline module is only imported if completekey has a non-None value. It looks like the only way to use readline and disable completion is to specify a do-nothing completer.

    class CmdSubclass(Cmd):
        # Other configuration
        # ...
    
        def complete(self, *args):
            pass