Skip to content

Terminal: display function signature and docstring popup after opening parentheses - #15412

Open
MahendraMula wants to merge 3 commits into
ipython:mainfrom
MahendraMula:feature/12789-signature-help-popup
Open

MahendraMula wants to merge 3 commits into
ipython:mainfrom
MahendraMula:feature/12789-signature-help-popup

Conversation

@MahendraMula

Copy link
Copy Markdown

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

  1. IPython/terminal/docstring.py

    • Implements DocstringTooltip using prompt-toolkit layout primitives (FloatContainer, Float(xcursor=True, ycursor=True), Window, and FormattedTextControl).
    • Implements dual-engine introspection: primary via jedi.Interpreter.get_signatures(), with fallback to shell._ofind() and inspect.signature / inspect.getdoc.
    • Runs introspection asynchronously in a thread executor (loop.run_in_executor) to keep typing responsive and non-blocking.
    • Includes debounced scheduling (delay=0.2s default) and a monotonic sequence counter (_request_id) to discard stale background responses when typing quickly.
    • Automatically hides the popup when the autocomplete/completion menu is active (~has_completions) or when prompt evaluation completes.
    • Uses class:completion-menu styling to respect light, dark, neutral, and nocolor themes.
  2. IPython/terminal/interactiveshell.py

    • Adds 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 DocstringTooltip during init_prompt_toolkit_cli().

    • Ensures docstring_tooltip.clear() is called when prompt input completes.

  3. IPython/terminal/tests/test_docstring.py

    • Adds 21 unit and integration tests covering:

      • Builtin functions, user functions, classes, bound methods, and lambdas.
      • Nested function calls and multiline arguments.
      • Definition headers, strings, and closed parentheses.
      • Custom dynamic __signature__ descriptors and non-callable objects.
      • Async debouncing, background task cancellation, and stale-request rejection.
      • Traitlet configuration options.

Verification

  • IPython/terminal/tests/test_docstring.py: 21 passed
  • IPython/terminal/tests/: 38 passed
  • tests/test_oinspect.py tests/test_shortcuts.py: 189 passed, 2 skipped
  • tests/test_completer.py: 268 passed, 2 skipped, 4 xfailed
  • git diff --check: Clean

Configuration

The popup is enabled by default and can be disabled with:

c.TerminalInteractiveShell.display_docstring_popup = False

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

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[enhancement] Display functions' docs in popup after opening parentheses

1 participant