Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-69605: Check for already imported modules in PyREPL module completion#139461

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
loic-simon wants to merge17 commits intopython:main
base:main
Choose a base branch
Loading
fromloic-simon:pyrepl-module-completion-check-for-already-imported-modules

Conversation

@loic-simon
Copy link
Contributor

@loic-simonloic-simon commentedSep 30, 2025
edited
Loading

This PR handles an edge-case when suggesting module imports in PyREPL (seethis comment):

If a module is already imported, the import machinery will only get submodules from it, even if a module of the same name is higher in the path. This can happen if eg. sys.path has been updated since the module was originaly imported.

The easiest way to reproduce this issue (and how I stumbled on it) is with stdlib modules imported during interpreter startup (before site customisation, so ignoring potential shadowing):

% mkdir collections% touch collections/__init__.py collections/foo.py% pythonPython 3.14.0rc2 [...]>>>from collectionsimport<TAB>>>>from collectionsimport fooTraceback (most recent call last):  File "<python-input-0>", line 1, in <module>    from collections import fooImportError: cannot import name 'foo' from 'collections' (/Users/loic/cpython/Lib/collections/__init__.py)>>>

This PR add a special case in_pyrepl.ModuleCompleter._find_modules that

  • check if the module to complete imports from is already imported
  • if yes, search for imports from the imported module location only, instead of using the global cache

It was a little tricky to get right, I'm not sure about everything 😅 but it pass all tests I could think off!

cc@tomasr8

@loic-simon
Copy link
ContributorAuthor

Ok, one of the new test fails on Windows x64/32 (but pass on arm)

I just setup and built Python on a Win 11 x64 to try to reproduce, the test pass 😵‍💫 (and the fix works)
If anyone has an idea of what may interfere? (Python 3.15.0a0 (main, Sep 30 2025, 23:36:53) [MSC v.1944 64 bit (AMD64)] on win32)

@python-cla-bot
Copy link

python-cla-botbot commentedOct 1, 2025
edited
Loading

All commit authors signed the Contributor License Agreement.

CLA signed

@picnixzpicnixz marked this pull request as draftOctober 3, 2025 13:21
@picnixz
Copy link
Member

I'm going to convert it into a draft until you deem this PR ready. That will also reduce the probability of someone clicking on the PR to review it (like me...) while it's not yet ready for.

loic-simon reacted with thumbs up emoji

@loic-simon
Copy link
ContributorAuthor

loic-simon commentedOct 3, 2025
edited
Loading

I'm going to convert it into a draft until you deem this PR ready. That will also reduce the probability of someone clicking on the PR to review it (like me...) while it's not yet ready for.

Thanks, I just fixed the failing test, this should be ready for review!

Sorry again for the noise, I was dealing with what turned out to be a importer cache issue, which I couldn't reproduce outside of the CI buildbots 😓

[edit] I just noticed I can convert to draft / mark ready myself, will do it next times!

@loic-simonloic-simon marked this pull request as ready for reviewOctober 5, 2025 13:38
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@pablogsalpablogsalAwaiting requested review from pablogsalpablogsal is a code owner

@lysnikolaoulysnikolaouAwaiting requested review from lysnikolaoulysnikolaou is a code owner

@ambvambvAwaiting requested review from ambvambv is a code owner

1 more reviewer

@ashm-devashm-devashm-dev requested changes

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

3 participants

@loic-simon@picnixz@ashm-dev

[8]ページ先頭

©2009-2025 Movatter.jp