Skip to content

Fix tab completion#2055

Open
mdboom wants to merge 2 commits intoNVIDIA:mainfrom
mdboom:fix-autocompletion
Open

Fix tab completion#2055
mdboom wants to merge 2 commits intoNVIDIA:mainfrom
mdboom:fix-autocompletion

Conversation

@mdboom
Copy link
Copy Markdown
Contributor

@mdboom mdboom commented May 8, 2026

This is a possible fix for #2053.

I almost never reach for monkey-patching as a solution, however in this case:

  • The alternatives are way worse and intrusive and force us into API design corners for the niche use case of tab completion (see my comments about the agent's other suggestions).

  • The monkeypatch is quite narrow -- it doesn't patch builtins that might have broad implications. It should only affect autocompletion with readline. A project like that might exist, but it's probably pretty niche. IPython and Jupyter are not affected by the bug to begin with, and the patch has no effect on them. (The patch is /installed/ with IPython, but then the code never gets called. I experimented with detecting IPython and not installing the patch, but it was complex, specific to IPython, and ultimately doesn't matter).

  • This monkeypatch is idempotent. If it gets cargo-culted to multiple projects, and those projects get imported in the same process, it will still work and be effective.

  • (Pending the CI run passing) It should be fine across all versions of Python we support, and there is a test here to confirm that going forward. If Python "fixes" the issue such that this patch is no longer needed, the test here should catch that and we can gate it at that point (as part of the usual "bring up on a new Python version" process).

@mdboom mdboom self-assigned this May 8, 2026
@mdboom mdboom added the cuda.core Everything related to the cuda.core module label May 8, 2026
@mdboom mdboom added this to the cuda.core v1.0.0 milestone May 8, 2026
@mdboom mdboom added bug Something isn't working P0 High priority - Must do! labels May 8, 2026
dev = Device(0)
dev.set_current()
mr = DeviceMemoryResource(dev)
assert not mr.is_ipc_enabled, "test setup: mr should not be IPC-enabled"
Copy link
Copy Markdown
Contributor Author

@mdboom mdboom May 8, 2026

Choose a reason for hiding this comment

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

This is only testing one specific class that we know broke things. If we accept this PR, we should probably add testing that /all/ of our Cython classes autocomplete correctly.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 8, 2026

@mdboom
Copy link
Copy Markdown
Contributor Author

mdboom commented May 8, 2026

Test failures indicate something wrong in the design of the test -- not a problem with the monkey-patch itself.

@mdboom mdboom requested a review from leofang May 8, 2026 14:38
Comment on lines +46 to +48
if not (hasattr(sys, "ps1") or sys.flags.inspect):
# Plain `python script.py`, `python -c ...`, pytest, etc.
return
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This doesn't seem quite correct, where if I just run python from a shell it drops me to a REPL that I should be able to get autocompletion with but sys.flags.inspect is 0.

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.

Yes, but ps1 is there, right. It WFM with python.

Comment on lines +53 to +57
# This works by overriding the `property` built-in with a custom subclass of
# property, but only in the rlcompleter module. This subclass overrides the
# `__instancecheck__` method to also return True for getset_descriptor and
# member_descriptor types, which are what Cython uses for properties on cdef
# classes.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Are we concerned about any implications of other modules Cython classes getset_descriptor objects?

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

Labels

bug Something isn't working cuda.core Everything related to the cuda.core module P0 High priority - Must do!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants