Skip to content

PyREPL: autocomplete built-in modules #134235

Closed

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

Activity

  1. gpshead commented on May 19, 2025

    @gpshead
    Member

    has anyone claimed this? I'm in the new sprinters room and would be happy to hand it to someone.

  2. newbery commented on May 19, 2025

    @newbery

    @gpshead, I wouldn't say I've claimed this yet but I'm looking at it. I'm in the same room. :)

  3. tomasr8 commented on May 19, 2025

    @tomasr8
    MemberAuthor

    @newbery I'm in 316, let me know if you need help 🙂

  4. tommix626 commented on May 19, 2025

    @tommix626
    Contributor

    @newbery I'm also looking into this, any updates now? Can I help along? I'm in 315.

  5. hyoung3 commented on May 19, 2025

    @hyoung3
    Contributor

    I have a fix. Trying to go through post steps of adding test cases, etc.

  6. tommix626 commented on May 19, 2025

    @tommix626
    Contributor

    Also have a fix! @hyoung3 want to meet and sync up? Hope to learn from you on the contribution process. (Are you at Pycon?)

  7. hyoung3 commented on May 19, 2025

    @hyoung3
    Contributor

    Hi @tommix626, yes. I'm in the beginners room.

  8. newbery commented on May 19, 2025

    @newbery

    @tommix626 , @hyoung3
    Cool. I walked away for a bit. Back now. You two need any more assist?

  9. hyoung3 commented on May 19, 2025

    @hyoung3
    Contributor

    @newbery we are trying to figure out a test now as one doesn't explicitly test the method we updated. If you have some ideas we'd be interested to hear.

  10. tommix626 commented on May 19, 2025

    @tommix626
    Contributor

    Update: me and @hyoung3 present @tomasr8 a solution that seems to work and are currently working together on writing tests for it.

  11. hyoung3 commented on May 19, 2025

    @hyoung3
    Contributor

    @tomasr8 we are having a "pulling our hair out" issue. You have a second to stop by?

  12. added
    stdlibStandard Library Python modules in the Lib/ directory
    on May 19, 2025
  13. added a commit that references this issue on May 19, 2025
  14. added a commit that references this issue on May 19, 2025
  15. gpshead commented on May 19, 2025

    @gpshead
    Member

    thanks everyone! this is featurey but i feel like this was intended for 3.14 with the autcomplete feature so i went ahead with the backport. if others or the release manager disagree, they can undo it in the 3.14 branch. :)

  16. tomasr8 commented on May 19, 2025

    @tomasr8
    MemberAuthor

    thanks everyone! this is featurey but i feel like this was intended for 3.14 with the autcomplete feature so i went ahead with the backport. if others or the release manager disagree, they can undo it in the 3.14 branch. :)

    Thank you! I wasn't sure whether to mark this as a bug or a feature, but it makes sense to backport this :)

  17. added a commit that references this issue on May 19, 2025
  18. added a commit that references this issue on Jul 12, 2025
  19. added a commit that references this issue on Aug 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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