Skip to content

Readline completion of module names in import statements #69605

Closed

Description

@vadmium
BPO 25419
Nosy @vadmium, @serhiy-storchaka, @MojoVampire
Dependencies
  • bpo-16182: readline: Wrong tab completion scope indices in Unicode terminals
  • Files
  • complete-import.patch
  • complete-import.v2.patch
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = None
    created_at = <Date 2015-10-16.11:16:48.120>
    labels = ['type-feature', 'library']
    title = 'Readline completion of module names in import statements'
    updated_at = <Date 2016-05-25.08:03:01.876>
    user = 'https://github.com/vadmium'

    bugs.python.org fields:

    activity = <Date 2016-05-25.08:03:01.876>
    actor = 'martin.panter'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = ['Library (Lib)']
    creation = <Date 2015-10-16.11:16:48.120>
    creator = 'martin.panter'
    dependencies = ['16182']
    files = ['40794', '42986']
    hgrepos = []
    issue_num = 25419
    keywords = ['patch']
    message_count = 6.0
    messages = ['253072', '253095', '253104', '253115', '253132', '266320']
    nosy_count = 3.0
    nosy_names = ['martin.panter', 'serhiy.storchaka', 'josh.r']
    pr_nums = []
    priority = 'normal'
    resolution = None
    stage = 'patch review'
    status = 'open'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue25419'
    versions = ['Python 3.6']

    Linked PRs

    Activity

    1. loic-simon commented on May 17, 2025

      @loic-simon
      Contributor

      Shouldn't we totally disable completion on import attributes?

      Since completions don't come from module attributes but current namespace, I find it pretty misleading, and unlikely to be useful.

      Eg. on 3.14 / current main,

      >>> from typing import Na<TAB>
      >>> from typing import NameError(

      while the user probably wanted to import NamedTuple: since we deferred completion of attributes, I believe it would be best to provide no suggestion at all.

    2. tomasr8 commented on May 17, 2025

      @tomasr8
      Member

      while the user probably wanted to import NamedTuple: since we deferred completion of attributes, I believe it would be best to provide no suggestion at all.

      That sounds reasonable to me! Would you like to send a PR for that? We'd most likely need to modify ModuleCompleter.get_completions to somehow distinguish between:

      • an invalid import statement which shouldn't disable completions (ImportParser.parse returns None) and
      • a valid import statement with no available completions which should disable completions

      Currently we just return an empty list for both.

    3. loic-simon commented on May 18, 2025

      @loic-simon
      Contributor

      That sounds reasonable to me! Would you like to send a PR for that? We'd most likely need to modify ModuleCompleter.get_completions

      Sure, I'll have a go at it, thanks for the pointers!

    4. tomasr8 commented on May 18, 2025

      @tomasr8
      Member

      Feel free to ping me if you need help!

    5. loic-simon commented on May 18, 2025

      @loic-simon
      Contributor

      Done, it was pretty straightforward indeed! 🚀

      Two other things I noted while working on it:

      • Submodule completion doesn't seem to always work, eg. from collections. doesn't suggest collections.abc (whereas http.server works). Do you know why / if this is can be fixed? Looks like pkgutils.iter_modules returns nothing, but I didn't investigate further.
      • Wouldn't it be cool if from typing <TAB> completed the import keyword? ImportParser.parse() returns None in such a case, and I don't know if there is precedent for completing after a space, might be a litte bit too magical?
    6. tomasr8 commented on May 18, 2025

      @tomasr8
      Member

      Thanks! I'll review it tomorrow.

      • This is expected, collections.abc is not a real module, same for os.path so pkgutil won't find it. One thing we could do is hardcode these modules but I haven't had the time to look into it.

      • Yup! I'm already working on that along with general improvements to the parser :)

    7. added a commit that references this issue on May 25, 2025
    8. added a commit that references this issue on May 25, 2025
    9. added a commit that references this issue on May 25, 2025
    10. added 2 commits that reference this issue on Jul 12, 2025
    11. added a commit that references this issue on Aug 4, 2025
    12. picnixz commented on Aug 30, 2025

      @picnixz
      Member

      Closing since this was actually completed.

    13. loic-simon commented on Aug 30, 2025

      @loic-simon
      Contributor

      That reminded me of this issue:

      This is expected, collections.abc is not a real module, same for os.path so pkgutil won't find it. One thing we could do is hardcode these modules but I haven't had the time to look into it.

      I went ahead and opened a small PR to do just that, let me know if it should become a separate issue!

    14. picnixz commented on Aug 30, 2025

      @picnixz
      Member

      Let's just reopen it.

    15. added a commit that references this issue on Sep 15, 2025
    16. added a commit that references this issue on Sep 15, 2025
    17. added a commit that references this issue on Oct 7, 2025
    18. added 6 commits that reference this issue on Jan 5, 2026
    19. loic-simon commented on Jan 5, 2026

      @loic-simon
      Contributor

      Nice, I think this issue can be closed again!

    20. added 2 commits that reference this issue on Feb 15, 2026
    21. added a commit that references this issue on Apr 5, 2026
    22. loic-simon commented on Apr 10, 2026

      @loic-simon
      Contributor
      • Wouldn't it be cool if from typing completed the import keyword? ImportParser.parse() returns None in such a case, and I don't know if there is precedent for completing after a space, might be a litte bit too magical?
      • Yup! I'm already working on that along with general improvements to the parser :)

      Hey @tomasr8, is this still on your radar? I'd love to see this land someday, can have a try at it if needed!

    23. tomasr8 commented on Apr 11, 2026

      @tomasr8
      Member
      • Wouldn't it be cool if from typing completed the import keyword? ImportParser.parse() returns None in such a case, and I don't know if there is precedent for completing after a space, might be a litte bit too magical?
      • Yup! I'm already working on that along with general improvements to the parser :)

      Hey @tomasr8, is this still on your radar? I'd love to see this land someday, can have a try at it if needed!

      Hey @loic-simon I was indeed working on that at some point (I even have a branch for it, but can't find it ATM), but feel free to pick it up! The import parser might also need some refactoring while you're at it :) I'll try to review it in a timely manner 😆

    24. added a commit that references this issue on Apr 25, 2026
    25. added a commit that references this issue on Jun 2, 2026
    26. added 3 commits that reference this issue on Oct 20, 2026
    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

      stdlibStandard 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