GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-140870: PyREPL auto-complete module attributes in import statements by loic-simon · Pull Request #140871 · python/cpython

Conversation

@loic-simon

@loic-simon loic-simon commented Nov 1, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Add the ability for _pyrepl._module_completer.ModuleCompleter to suggest attributes, in addition to modules.

If the module to import from is not imported yet, ask the user if they want to import it.
This is done by adding the notion of completion action to _pyrepl.completing_reader.CompletingReader:

  • get_completions can return a completion action, in addtion to the suggestions list
  • A completion action is a prompt to show + a callback to call if the user press TAB again
  • The callback can return a message to show instead (here, if import failed)
  • After the callback is fired, get_completions is called again, so it can propose new results (here, module attributes)
  • If the user does any other input than TAB when the prompt is shown, the action is discarded

Other changes:

  • I had to tweak a little the code used to display a message below the prompt, to handle the case when it doesn't fit on the console
  • Some unrelated tests to get the coverage rate of _module_completer to 100% (in a separate commit, I can remove it if needed) -> gh-140870: Full coverage for _pyrepl._module_completer #143244

Interactive WebAssembly demo (up to date): https://pyrepl-attributes-import-completion.pages.dev

Possible improvement: make modules printing stuff when imported not mess with the prompt ; see this Discourse message

  • Issue: PyREPL: auto-complete module attributes in import statements #140870

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@loic-simon
loic-simon requested review from ambv, lysnikolaou and pablogsal as code owners November 1, 2025 00:53
@bedevere-app bedevere-app Bot added the awaiting review label Nov 1, 2025
@loic-simon loic-simon changed the title gh-14870: PyREPL auto-complete module attributes in import statements gh-140870: PyREPL auto-complete module attributes in import statements Nov 1, 2025
@bedevere-app bedevere-app Bot mentioned this pull request Nov 1, 2025
PyREPL: auto-complete module attributes in import statements #140870
Closed
@tomasr8

tomasr8 commented Dec 28, 2025

Copy link
Copy Markdown
Member

Some unrelated tests to get the coverage rate of _module_completer to 100% (in a separate commit, I can remove it if needed)

Could you extract those into a separate PR? I think those are nice to have in any case and we can merge it quickly :)

loic-simon reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@tomasr8
tomasr8 self-requested a review December 28, 2025 11:53
@loic-simon loic-simon mentioned this pull request Dec 28, 2025
gh-140870: Full coverage for _pyrepl._module_completer #143244
Merged
@loic-simon

loic-simon commented Dec 28, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

Could you extract those into a separate PR? I think those are nice to have in any case and we can merge it quickly :)

Sure, #143244

tomasr8 reacted with heart emoji
All reactions
  • ❤️ 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@tomasr8

tomasr8 commented Dec 28, 2025

Copy link
Copy Markdown
Member

Quick initial question, can we disable the prompt for stdlib modules? I don't think there should be any concerns with auto-importing from the stdlib

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@loic-simon

loic-simon commented Dec 28, 2025

Copy link
Copy Markdown
Contributor Author

We could, yes. I don't think we can decide to auto-import solely on module name (to take care of potential shadowing by first/third-party modules), so we would need to look the module spec location, but since we already have self._is_stdlib_module and self._global_cache that should be easy and fast!

(I'll won't be to get my hands on the code until early January tho)

tomasr8 reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@tomasr8

tomasr8 commented Dec 29, 2025

Copy link
Copy Markdown
Member

Yup, we definitely need to look at the module location, not just the name

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@loic-simon loic-simon mentioned this pull request Jan 1, 2026
gh-69605: Check for already imported modules in PyREPL module completion #139461
Merged
@loic-simon

loic-simon commented Jan 10, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

The new test is quite platform-dependant (I just fixed an iOS + Andoid only fail), it may be a good idea to trigger buildbots on this PR!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

StanFromIreland
StanFromIreland reviewed Jan 11, 2026
View reviewed changes
Comment thread Lib/_pyrepl/_module_completer.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

@StanFromIreland

StanFromIreland commented Jan 11, 2026

Copy link
Copy Markdown
Member

Thanks!

trigger buildbots on this PR

I can run the buildbots, do you want them now?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@loic-simon

loic-simon commented Jan 11, 2026

Copy link
Copy Markdown
Contributor Author

I can run the buildbots, do you want them now?

Yes please! I don't plan any more change on my side.

StanFromIreland reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@StanFromIreland StanFromIreland added the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Jan 11, 2026
@bedevere-bot

bedevere-bot commented Jan 11, 2026

Copy link
Copy Markdown

🤖 New build scheduled with the buildbot fleet by @StanFromIreland for commit 9c80367 🤖

Results will be shown at:

https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F140871%2Fmerge

If you want to schedule another build, you need to add the 🔨 test-with-buildbots label again.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-bot bedevere-bot removed the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Jan 11, 2026
@loic-simon

loic-simon commented Jan 11, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

Okay that was useful, buildbot failures analysis:

  • A lot of fails on compression.ztsd not suggestingcompress attribute, which is expected since it is an optional module, I'll use a better test case 😅
  • All Reafleaks buildbots fail on collections.abc not suggesting Buffer, I don't know why but I suppose it's expected too, I'll use another test case
  • iOS ARM64 Simulator has a lot of other fails, I don't quite understand what's going on 🤔
    • maybe an importer cache issue like last time? I'll add some invalidation
Details

Missing compression.ztsd:

AMD64 Debian root PR
AMD64 RHEL8 FIPS Only Blake2 Builtin Hash PR
AMD64 RHEL8 LTO + PGO PR
AMD64 RHEL8 LTO PR
AMD64 RHEL8 PR
AMD64 RHEL8 Refleaks PR
AMD64 Ubuntu Shared PR
ARM64 MacOS M1 NoGIL PR
ARM64 MacOS M1 Refleaks NoGIL PR
ARM64 Raspbian Debug PR
ARM64 Raspbian PR
PPC64LE RHEL8 LTO + PGO PR
PPC64LE RHEL8 LTO PR
PPC64LE RHEL8 PR
PPC64LE RHEL8 Refleaks PR
s390x Fedora Stable Clang Installed PR
s390x Fedora Stable Clang PR
s390x Fedora Stable LTO + PGO PR
s390x Fedora Stable LTO PR
s390x Fedora Stable PR
s390x Fedora Stable Refleaks PR
s390x RHEL8 LTO + PGO PR
s390x RHEL8 LTO PR
s390x RHEL8 PR
s390x RHEL8 Refleaks PR
s390x RHEL9 LTO + PGO PR
s390x RHEL9 LTO PR
s390x RHEL9 PR
s390x RHEL9 Refleaks PR
x86-64 MacOS Intel ASAN NoGIL PR
x86-64 MacOS Intel NoGIL PR

Missing collections.abc.Buffer:

Missing AMD64 CentOS9 NoGIL Refleaks PR
AMD64 FreeBSD Refleaks PR
AMD64 RHEL8 Refleaks PR
ARM64 MacOS M1 Refleaks NoGIL PR
PPC64LE RHEL8 Refleaks PR
s390x Fedora Stable Refleaks PR
s390x RHEL8 Refleaks PR
s390x RHEL9 Refleaks PR

A lot of fails:

iOS ARM64 Simulator PR
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@loic-simon
loic-simon requested a review from StanFromIreland January 24, 2026 14:30
@loic-simon

loic-simon commented Jan 24, 2026

Copy link
Copy Markdown
Contributor Author

@StanFromIreland if you could trigger a builbots run again, that would be great! Thanks

StanFromIreland reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@StanFromIreland StanFromIreland added the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Jan 24, 2026
@bedevere-bot

bedevere-bot commented Jan 24, 2026

Copy link
Copy Markdown

🤖 New build scheduled with the buildbot fleet by @StanFromIreland for commit da6cf7f 🤖

Results will be shown at:

https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F140871%2Fmerge

If you want to schedule another build, you need to add the 🔨 test-with-buildbots label again.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-bot bedevere-bot removed the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Jan 24, 2026
@loic-simon

loic-simon commented Jan 24, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

Ok, good news: iOS Siumlator is green!

Bad news: all Refleaks builds now fail ~all attribute completion tests 😞

Good news: I reproduced in local (python -m test pass, -m test -R: fails), on it!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@loic-simon

loic-simon commented Jan 24, 2026

Copy link
Copy Markdown
Contributor Author

That check fail doesn't look related to this PR (Error: The template is not valid. .github/workflows/build.yml (Line: 720, Col: 24): Error reading JToken from JsonReader. Path '', line 0, position 0.)

Refleak tests pass locally, may I ask for a last run with 🔨 test-with-refleak-buildbots @StanFromIreland, just to be sure? Thanks a lot!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@StanFromIreland

StanFromIreland commented Jan 24, 2026

Copy link
Copy Markdown
Member

That check fail doesn't look related to this PR (Error: The template is not valid. .github/workflows/build.yml (Line: 720, Col: 24): Error reading JToken from JsonReader. Path '', line 0, position 0.)

However, it is. You need to update the branch, the current version is incompatible with our CI.

loic-simon reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

loic-simon and others added 13 commits April 5, 2026 18:54
@loic-simon @pablogsal
pythongh-140870 PyREPL: add import completion for attributes
099cf71
@loic-simon @pablogsal
Improve behavior when both submodules + prompt
42e734c
@loic-simon @pablogsal
Auto-import stdlib modules
78e0ce6
@loic-simon @pablogsal
Blacklist some stdlib modules from auto-import
4af851b
@loic-simon @pablogsal
Fix tests post rebase
61e797a
@loic-simon @pablogsal
Improve & test auto-import blacklist
f02fc8f
@loic-simon @pablogsal
Add _ios_support to auto import blacklist
17599ed
@loic-simon @pablogsal
Fix tests requiring tkinter
5125a0d
@loic-simon @pablogsal
Avoid charged terminology
3bb88d1
@loic-simon @pablogsal
Use always available modules in tests + invalidate caches
1013912
@loic-simon @pablogsal
Don't test with html module either
0d1105f
@loic-simon @pablogsal
Fix refleaks in test_pyrepl.py
7b9a26d
@pablogsal
Fix pyrepl import completion edge cases
d57de37
Tighten the pyrepl completer around a few import-completion edge cases.
Relative imports now share one resolver, find_spec failures no longer
bubble out, failed-import tracking resets when sys.path changes, and
double-tab import actions are cleared once consumed.

The patch also keeps empty message lines intact in reader output and
updates the targeted tests and comments to match the intended behavior.
@pablogsal
pablogsal force-pushed the pyrepl-import-completion-for-attributes branch from a7116a1 to d57de37 Compare April 5, 2026 18:13
@pablogsal

pablogsal commented Apr 5, 2026

Copy link
Copy Markdown
Member

Thanks a lot @loic-simon! I made a small commit fixing a bunch of small things and adding fixes for edge cases and related test cleanups. I also rebased the branch onto the latest main and reran the relevant smoke/tests locally.

With this I am happy to land :)

StanFromIreland and loic-simon reacted with hooray emoji
All reactions
  • 🎉 2 reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

pablogsal
pablogsal approved these changes Apr 5, 2026
View reviewed changes

@pablogsal pablogsal left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

LGTM

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@bedevere-app bedevere-app Bot added awaiting merge and removed awaiting review labels Apr 5, 2026
@pablogsal
pablogsal enabled auto-merge (squash) April 5, 2026 18:25
@loic-simon

loic-simon commented Apr 5, 2026

Copy link
Copy Markdown
Contributor Author

Thanks a lot Pablo! If don't want to abuse your time, but while you have PyREPL import suggestions in mind, I have this one-line bugfix PR that could use a merge too 😄

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@pablogsal

pablogsal commented Apr 5, 2026

Copy link
Copy Markdown
Member

Thanks a lot Pablo! If don't want to abuse your time, but while you have PyREPL import suggestions in mind, I have this one-line bugfix PR that could use a merge too 😄

Landed! Thank you for your time :)

loic-simon reacted with heart emoji
All reactions
  • ❤️ 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@pablogsal
pablogsal disabled auto-merge April 5, 2026 18:32
@loic-simon

loic-simon commented Apr 5, 2026

Copy link
Copy Markdown
Contributor Author

Heh, of course these two would conflict 😅 fixing it

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@loic-simon
Merge branch 'main' into pyrepl-import-completion-for-attributes
d7aa3b5
@pablogsal
pablogsal enabled auto-merge (squash) April 5, 2026 18:46
@pablogsal
pablogsal merged commit b07becb into python:main Apr 5, 2026
60 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot removed the awaiting merge label Apr 5, 2026
@pablogsal

pablogsal commented Apr 5, 2026

Copy link
Copy Markdown
Member

Thanks a lot for your contribution @loic-simon 🚀

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@python python deleted a comment from bedevere-bot Apr 5, 2026
ljfp pushed a commit to ljfp/cpython that referenced this pull request Apr 25, 2026
@loic-simon @pablogsal @ljfp
pythongh-140870: PyREPL auto-complete module attributes in import sta…
597be3e
…tements (python#140871)

Co-authored-by: Pablo Galindo Salgado <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@pablogsal pablogsal pablogsal approved these changes
@lysnikolaou lysnikolaou Awaiting requested review from lysnikolaou lysnikolaou is a code owner
@ambv ambv Awaiting requested review from ambv ambv is a code owner
@tomasr8 tomasr8 Awaiting requested review from tomasr8
@StanFromIreland StanFromIreland Awaiting requested review from StanFromIreland

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

5 participants

@loic-simon @tomasr8 @StanFromIreland @bedevere-bot @pablogsal
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.