Skip to content

PyREPL: autocomplete built-in modules #134235

@tomasr8

Description

@tomasr8

Feature or enhancement

Proposal:

Currently, built-in modules (i.e. sys) are not autocompleted in the new REPL. For instance, typing import sy<tab> does not offer sys as a completion possibility.

This is because we use pkgutil.iter_modules under the hood. Since built-in modules have no underlying .py file, they don't show up.

It would be great if the autocomplete could still work with these modules. One possibility would be looking at sys.builtin_module_names and combining it with the results of pkgutil.iter_modules.

The relevant code is in this class:

class ModuleCompleter:
"""A completer for Python import statements.

Here's how I think we can implement it:

  • Find built-in modules by looking at sys.builtin_module_names
  • Merge the results with ModuleCompleter.global_cache (might need changing how we represent the modules)

IIUC we only have built-in top-level modules, not submodules, so that should simplify the implementation.

Please don't pick up this issue, I'd like to reserve it for someone at the PyConUS sprints :)

Has this already been discussed elsewhere?

This is a minor feature, which does not need previous discussion elsewhere

Links to previous discussion of this feature:

No response

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    easystdlibStandard Library Python modules in the Lib/ directorytopic-replRelated to the interactive shelltype-featureA feature request or enhancement

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions