Skip to content

gh-149167: PyREPL autocomplete imports to only display public members - #156146

Open
edvilme wants to merge 8 commits into
python:mainfrom
edvilme:gh-149167-pyrepl-module-complete
Open

edvilme wants to merge 8 commits into
python:mainfrom
edvilme:gh-149167-pyrepl-module-complete

Conversation

@edvilme

@edvilme edvilme commented Aug 21, 2026 •

Copy link
Copy Markdown
Contributor

Updates PyREPL autocomplete on import statements to only expose public members if declared with __all__

Before

Screenshot 2026-08-20 at 10 42 50 p m

After

Screenshot 2026-08-20 at 10 39 22 p m

…embers

Adds a mechanism that filters a module's public members for showing on autocomplete.
@edvilme

edvilme commented Aug 22, 2026

Copy link
Copy Markdown
Contributor Author

CC @ambv @pablogsal

@loic-simon loic-simon left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two notes:

  • The suggested imports are filtered by self.is_suggestion_match later, which means that if a module explicitely exposed a "private" name (starting with an _) in its __all__, it will be excluded unless the user search for private arguments. That may be a case edgy enough to ignore?
  • If the user search for a name that can be imported but is not in __all__, do we really want the REPL to hide it? I quite like the current behavior with _-private names (hide them unless explicitely asked for), so maybe we could restrict to __all__ only for bare fron json import completions, and use dir otherwise? This is a more opinionatred question, tied to the debates around PEP 842-44 😅

Comment thread Lib/_pyrepl/_module_completer.py Outdated
@edvilme

edvilme commented Aug 28, 2026 •

Copy link
Copy Markdown
Contributor Author

Hello @loic-simon thank you for your feedback and for pointing out those overlooks. I would definitely keep an eye out on PEP 842-44 and discussions for many of those decisions.

  1. I think you are right in not mixing heuristics. If a module exposes __all__ we should respect those members and not hide regardless of them starting with _ (they are explicitly exposed).
  2. This definitely sounds more opinionated and will read the discussions on the PEP as well as other people's thoughts.
  3. Will remove the redundant comment ;)

Added comment on discussion https://discuss.python.org/t/python-api-exposure-mechanisms-public-internal-determining-status-quo/108869/35

if hasattr(imported_module, '__all__'): # Return __all__ directly
names = [
attr_name for attr_name in imported_module.__all__
if attr_name.startswith(prefix) and attr_name.isidentifier()

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants