-
-
Notifications
You must be signed in to change notification settings - Fork 33k
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
gh-69605: Hardcode some stdlib submodules in PyREPL module completion (os.path, collections.abc...) #138268
Conversation
Misc/NEWS.d/next/Core_and_Builtins/2025-08-30-17-15-05.gh-issue-69605.KjBk99.rst
Outdated
Show resolved
Hide resolved
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. |
Yeah, I wondered about that, I'll check if we have a reliable and fast way to check this. Just looking at A side note on this: when testing the current behavior by creating a folder % mkdir collections
% touch collections/__init__.py collections/foo.py
% python
Python 3.14.0rc2 [...]
>>> from collections import <TAB>
>>> from collections import foo
Traceback (most recent call last):
File "<python-input-0>", line 1, in <module>
from collections import foo
ImportError: 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 in |
Thanks @loic-simon for the PR, and @ambv for merging it 🌮🎉.. I'm working now to backport this PR to: 3.14. |
…letion (os.path, collections.abc...) (pythonGH-138268) (cherry picked from commit 537133d) Co-authored-by: Loïc Simon <[email protected]> Co-authored-by: Łukasz Langa <[email protected]>
GH-138943 is a backport of this pull request to the 3.14 branch. |
Adressed in #139461. |
From #69605 (comment):
This PR adds a hardcoded dictionary of unusual standard library submodules that
pkgutil.iter_modules
can't find despite them being importable, so we can suggest them anyway.The hardcoded dictionary comes from checking all documented 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