Terminal: display function signature and docstring popup after opening parentheses - #15412
Open
MahendraMula wants to merge 3 commits into
Open
MahendraMula wants to merge 3 commits into
MahendraMula wants to merge 3 commits into
Conversation
Closes ipython#12789. Implements signature and docstring popup in terminal IPython when the user opens parentheses on a callable (or navigates inside call arguments). - Adds DocstringTooltip in IPython/terminal/docstring.py using prompt-toolkit's FloatContainer, Float (xcursor=True, ycursor=True), Window, and FormattedTextControl. - Reuses Jedi get_signatures() with fallback to shell._ofind() and inspect. - Avoids UI blocking by running introspection in a thread pool executor. - Debounces requests to prevent introspection on every keystroke and cancels stale requests when typing continues. - Disables popup when completion menu is open (~has_completions) or cell execution finishes (~is_done). - Adds display_docstring_popup and docstring_popup_delay traitlets to TerminalInteractiveShell. - Adds comprehensive unit and async test coverage in IPython/terminal/tests/test_docstring.py.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Closes #12789.
Summary
Implements a signature and docstring popup in terminal IPython when typing an opening parenthesis
(on callables or editing arguments inside function calls, providing a built-in experience similar to ptpython.Changes
IPython/terminal/docstring.pyDocstringTooltipusing prompt-toolkit layout primitives (FloatContainer,Float(xcursor=True, ycursor=True),Window, andFormattedTextControl).jedi.Interpreter.get_signatures(), with fallback toshell._ofind()andinspect.signature/inspect.getdoc.loop.run_in_executor) to keep typing responsive and non-blocking.delay=0.2sdefault) and a monotonic sequence counter (_request_id) to discard stale background responses when typing quickly.~has_completions) or when prompt evaluation completes.class:completion-menustyling to respect light, dark, neutral, and nocolor themes.IPython/terminal/interactiveshell.pyAdds configurable traitlets to
TerminalInteractiveShell:display_docstring_popup:Bool(True)to enable/disable the popup.docstring_popup_delay:Float(0.2)to adjust the debounce delay.Attaches
DocstringTooltipduringinit_prompt_toolkit_cli().Ensures
docstring_tooltip.clear()is called when prompt input completes.IPython/terminal/tests/test_docstring.pyAdds 21 unit and integration tests covering:
__signature__descriptors and non-callable objects.Verification
IPython/terminal/tests/test_docstring.py: 21 passedIPython/terminal/tests/: 38 passedtests/test_oinspect.py tests/test_shortcuts.py: 189 passed, 2 skippedtests/test_completer.py: 268 passed, 2 skipped, 4 xfailedgit diff --check: CleanConfiguration
The popup is enabled by default and can be disabled with: