Skip to content

REPL tab completion of a global name imports lazily imported modules #159266

Open

Description

@brittanyrey

Tab completion from the repl loads lazily imported modules during completion.

Repro

Create a sample file which prints on import

# noisy.py
print("*** noisy imported ***")

From the repl

>>> lazy import noisy
>>> import sys; 'noisy' in sys.modules
False
>>> no<tab>*** noisy imported ***
>>> 'noisy' in sys.modules
True

Linked PRs

Activity

  1. terryjreedy commented on Oct 12, 2026

    @terryjreedy
    Member

    A tab after space does not trigger tab completion for me, and should not. Did you actually enter no<tab>? If so, I think the current behavior is correct. If one want to access library_module_with_long_name.some_attribute, one would want lo<tab to display library_module_with_long_name as a possible completion. The purpose of lazy imports is to speed program startup by skipping imports that are not immediately needed, and often, which may never by needed). It is irrelevant in interactive mode.

  2. added
    pendingThe issue will be closed if no feedback is provided
    on Oct 12, 2026
  3. brittanyrey commented on Oct 13, 2026

    @brittanyrey
    ContributorAuthor

    With respect to the additional space, that was an oversight (I was trying to make the repro easier to read).
    I have now updated the example above to remove the space as that is the exact behavior needed to trigger the reification.

    The proposed implementation would still provide library_module_with_long_name as an option, without loading the module.

    >>> lazy import library_module_with_long_name
    >>> li<tab><tab>
    library_module_with_long_name  license                        list

    The module stays lazy and is still listed for the user. The one change is that we would no longer apply coloring for the imported module/attrs until after they are reified.

    This specific corner case is a correctness fix, not a performance optimization.

  4. yeti107 commented on Oct 13, 2026

    @yeti107

    Hi! Just wondering if this is still open? If it is i'd love to have it assigned to me so I can start work on it ASAP.

    Thanks

  5. brittanyrey commented on Oct 13, 2026

    @brittanyrey
    ContributorAuthor

    Hi @yeti107,
    There is already a linked PR #159267 addressing the issue.
    Thanks for your interest.

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

    pendingThe issue will be closed if no feedback is providedtopic-lazy-importstopic-replRelated to the interactive shell

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions