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: Hardcode some stdlib submodules in PyREPL module completion (os.path, collections.abc...)#138268

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

Conversation

@loic-simon
Copy link
Contributor

@loic-simonloic-simon commentedAug 30, 2025
edited by bedevere-appbot
Loading

From#69605 (comment):

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.

This PR adds a hardcoded dictionary of unusual standard library submodules thatpkgutil.iter_modules can't find despite them being importable, so we can suggest them anyway.

The hardcoded dictionary comes from checking alldocumented modules to find which submodules_pyrepl._module_completer.ModuleCompleter was unable to detect.

I wrote a test to ensure all hardcoded modules are indeed importable, but I'm not sure we can programatically detect eventual new modules so we don't forget to add them, but it should be rare enough to not be too much a concern.

cc@tomasr8

@python-cla-bot
Copy link

python-cla-botbot commentedAug 30, 2025
edited
Loading

All commit authors signed the Contributor License Agreement.

CLA signed

@tomasr8
Copy link
Member

Thanks! I was planning to implement this at some point, but you beat me to it :) I haven't checked too deeply, but we should make sure to only autocomplete these submodules when we are sure they are coming from the stdlib. We do not want to autocomplete them when a user intentionally shadows an stdlib module with their own because in that case they might not exist.

@loic-simon
Copy link
ContributorAuthor

but we should make sure to only autocomplete these submodules when we are sure they are coming from the stdlib. We do not want to autocomplete them when a user intentionally shadows an stdlib module with their own because in that case they might not exist.

Yeah, I wondered about that, I'll check if we have a reliable and fast way to check this. Just looking atModuleInfo.file_finder.path to see if it is relative to the stdlib path may do the trick!


A side note on this: when testing the current behavior by creating a foldercollections with__init__.py andfoo.py in it, the current mechanism suggestcollections.foo, but is cannot be imported... becausecollections was already imported at startup (because of interactive mode):

% 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)>>>% python -c "from collections import foo; print(foo)"<module 'collections.foo' from '/Users/loic/test/collections/foo.py'>

Not directly related, but it may be cool to check if the name to complete is already insys.modules, and if yes only suggest imports from the location of the imported module.

@ambvambv merged commit537133d intopython:mainSep 15, 2025
89 of 91 checks passed
@ambvambv added the needs backport to 3.14bugs and security fixes labelSep 15, 2025
@miss-islington-app
Copy link

Thanks@loic-simon for the PR, and@ambv for merging it 🌮🎉.. I'm working now to backport this PR to: 3.14.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull requestSep 15, 2025
…letion (os.path, collections.abc...) (pythonGH-138268)(cherry picked from commit537133d)Co-authored-by: Loïc Simon <loic.simon@napta.io>Co-authored-by: Łukasz Langa <lukasz@langa.pl>
@bedevere-app
Copy link

GH-138943 is a backport of this pull request to the3.14 branch.

@loic-simon
Copy link
ContributorAuthor

Not directly related, but it may be cool to check if the name to complete is already insys.modules, and if yes only suggest imports from the location of the imported module.

Adressed in#139461.

ambv added a commit that referenced this pull requestOct 7, 2025
…pletion (os.path, collections.abc...) (GH-138268) (GH-138943)(cherry picked from commit537133d)Co-authored-by: Loïc Simon <loic.simon@napta.io>Co-authored-by: Łukasz Langa <lukasz@langa.pl>
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@aiskaiskaisk left review comments

@AA-TurnerAA-TurnerAA-Turner left review comments

@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

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

5 participants

@loic-simon@tomasr8@aisk@AA-Turner@ambv

[8]ページ先頭

©2009-2025 Movatter.jp