Skip to content

cmd.py command completion does not work with libedit #102130

Closed
@keeely

Description

@keeely

Bug report

As title, the Homebrew community has switched to libedit readline as of Python 3.11. There exists a gnureadline package which allows one to continue using the gnu readline, but unfortunately cmd.py will continue to use the libedit one, and that doesn't always work properly.

Your environment

Python 3.11 MacOs Ventura.

Here's some code that won't work with libedit readline:

import cmd

class MyShell(cmd.Cmd):
    def do_command(self, _arg):
        print(f"running {self}")

MyShell().cmdloop()

Tab-completion appears to fail on Homebrew python 3.11, I suspect due to the libedit readline. The code works fine with Homebrew python versions up to 3.10 which use gnu readline. Also, if you install gnureadline and change all occurrences of import readline in cmd.py to import gnureadline as readline the cmd module works perfectly.

So in summary could we fix cmd.py to work correctly with libedit as well as gnu readline? Or, failing that provide some fairly easy means of overriding the readline used by cmd.py without resorting to nasty monkey patching.

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibPython modules in the Lib dirtype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions